-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
216 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/guillotine/typeFieldResolvers/contentMetaFieldsResolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type {Content} from '/lib/xp/content'; | ||
import type {ImageId} from '/lib/types'; | ||
import type {MetafieldsSiteConfig} from '../types/MetafieldsSiteConfig'; | ||
|
||
|
||
import {commaStringToArray} from '/lib/common/commaStringToArray'; | ||
import {findStringValueInObject} from '/lib/common/findStringValueInObject'; | ||
import {ImageIdBuilder} from '/lib/types'; | ||
|
||
|
||
export function findImageIdInContent({ | ||
content, | ||
siteConfig | ||
}: { | ||
content: Content | ||
siteConfig: MetafieldsSiteConfig | ||
}): ImageId|undefined { | ||
const userDefinedPaths = siteConfig.pathsImages || ''; | ||
const userDefinedArray = userDefinedPaths ? commaStringToArray(userDefinedPaths) : []; | ||
const userDefinedValue = userDefinedPaths ? findStringValueInObject(content, userDefinedArray, siteConfig.fullPath) : null; | ||
return ImageIdBuilder.from( | ||
userDefinedValue | ||
|| content.data.image as string | ||
|| content.data.images as string | ||
) || undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type {Content, Site} from '/lib/xp/content'; | ||
import type {ImageId} from '/lib/types'; | ||
import type {MetafieldsSiteConfig} from '../types/MetafieldsSiteConfig'; | ||
|
||
|
||
import {APP_NAME_PATH, MIXIN_PATH} from '/lib/common/constants'; | ||
import {findImageIdInContent} from '/lib/common/findImageIdInContent'; | ||
import {ImageIdBuilder} from '/lib/types'; | ||
|
||
|
||
export function getImageId({ | ||
content, | ||
site, | ||
siteConfig | ||
} :{ | ||
content: Content | ||
site: Site<MetafieldsSiteConfig> | ||
siteConfig: MetafieldsSiteConfig | ||
}): ImageId|undefined { | ||
// 1. Override image set on content | ||
if(content.x?.[APP_NAME_PATH]?.[MIXIN_PATH]?.seoImage) { | ||
return ImageIdBuilder.from(content.x[APP_NAME_PATH][MIXIN_PATH].seoImage as string); | ||
} | ||
|
||
// 2. Try to find an image within the content isself | ||
const imageId = findImageIdInContent({content, siteConfig}); | ||
if (imageId) { | ||
return imageId; | ||
} | ||
|
||
// 3. Fallback to siteConfig image | ||
if (siteConfig.seoImage) { | ||
return ImageIdBuilder.from(siteConfig.seoImage); | ||
} | ||
|
||
// 4. Fallback to image on siteContent | ||
return findImageIdInContent({content: site, siteConfig}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
10 changes: 6 additions & 4 deletions
10
src/main/resources/lib/brand.ts → src/main/resources/lib/types/brand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//────────────────────────────────────────────────────────────────────────────── | ||
// Type imports | ||
//────────────────────────────────────────────────────────────────────────────── | ||
import type {Content} from '@enonic-types/lib-content'; | ||
import type {Branded} from '/lib/types/Branded'; | ||
import type { | ||
GraphQLBoolean, | ||
GraphQLContent, | ||
GraphQLID, | ||
GraphQLInt, | ||
GraphQLFloat, | ||
GraphQLJson, | ||
GraphQLDateTime, | ||
GraphQLDate, | ||
GraphQLLocalTime, | ||
GraphQLLocalDateTime, | ||
GraphQLMediaImage, | ||
GraphQLMetaFields, | ||
GraphQLString, | ||
} from '/lib/types/Guillotine'; | ||
|
||
|
||
//────────────────────────────────────────────────────────────────────────────── | ||
// Value imports | ||
//────────────────────────────────────────────────────────────────────────────── | ||
import {brand} from '/lib/types/brand'; | ||
|
||
|
||
//────────────────────────────────────────────────────────────────────────────── | ||
// ExportedtTypes | ||
//────────────────────────────────────────────────────────────────────────────── | ||
export type {MetafieldsSiteConfig} from '/lib/types/MetafieldsSiteConfig'; | ||
|
||
export declare type BaseFolder = Content<{}, 'base:folder'>; | ||
|
||
export declare type ImageId = Branded<string, 'ImageId'>; | ||
|
||
export declare type MediaImage = Content<{ | ||
media: { | ||
altText?: string | ||
artist?: string | ||
attachment: string | ||
caption?: string | ||
copyright?: string | ||
focalPoint: { | ||
x: number | ||
y: number | ||
} | ||
tags?: string // with comma? | ||
} | ||
}, 'media:image'>; | ||
|
||
//────────────────────────────────────────────────────────────────────────────── | ||
// Exported values | ||
//────────────────────────────────────────────────────────────────────────────── | ||
export const ImageIdBuilder = brand<ImageId>(); | ||
|
||
export const GraphQLBooleanBuilder = brand<GraphQLBoolean>(); | ||
export const GraphQLDateBuilder = brand<GraphQLDate>(); | ||
export const GraphQLDateTimeBuilder = brand<GraphQLDateTime>(); | ||
export const GraphQLFloatBuilder = brand<GraphQLFloat>(); | ||
export const GraphQLIDBuilder = brand<GraphQLID>(); | ||
export const GraphQLIntBuilder = brand<GraphQLInt>(); | ||
export const GraphQLJsonBuilder = brand<GraphQLJson>(); | ||
export const GraphQLLocalDateTimeBuilder = brand<GraphQLLocalDateTime>(); | ||
export const GraphQLLocalTimeBuilder = brand<GraphQLLocalTime>(); | ||
export const GraphQLStringBuilder = brand<GraphQLString>(); | ||
|
||
export const GraphQLContentBuilder = brand<GraphQLContent>(); | ||
export const GraphQLMediaImageBuilder = brand<GraphQLMediaImage>(); | ||
export const GraphQLMetaFieldsBuilder = brand<GraphQLMetaFields>(); |
Oops, something went wrong.