diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index 2eec9fe1..14438c26 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -408,7 +408,7 @@ export class ContentType { * @param parents * @returns */ - public static getFieldValue(data: any, parents: string[]): any { + public static getFieldValue(data: any, parents: string[]): string | string[] { let fieldValue = []; let crntPageData = data; @@ -575,8 +575,7 @@ export class ContentType { fieldValue === null || fieldValue === undefined || fieldValue === '' || - (Array.isArray(fieldValue) && fieldValue.length === 0) || - (typeof fieldValue === 'string' && fieldValue.length === 0) || + fieldValue.length === 0 || fieldValue === DefaultFieldValues.faultyCustomPlaceholder ) { emptyFields.push(fields); diff --git a/src/services/PagesParser.ts b/src/services/PagesParser.ts index 87d7fc33..bd2e339f 100644 --- a/src/services/PagesParser.ts +++ b/src/services/PagesParser.ts @@ -333,32 +333,19 @@ export class PagesParser { // Revalidate as the array could have been empty if (fieldValue) { - // Handle both string and object formats for the field value - let imageValue: string; - if (typeof fieldValue === 'string') { - imageValue = fieldValue; - } else if (typeof fieldValue === 'object' && fieldValue.src) { - // Handle object format like { src: "filename.jpg", title: "title" } - imageValue = fieldValue.src; + // Check if the value already starts with https - if that is the case, it is an external image + if (fieldValue.startsWith('http')) { + page.fmPreviewImage = fieldValue; } else { - // Skip processing if the value is neither a string nor an object with src - imageValue = null; - } + let staticPath = join(wsFolder.fsPath, staticFolder || '', fieldValue); - if (imageValue) { - // Check if the value already starts with https - if that is the case, it is an external image - if (imageValue.startsWith('http')) { - page.fmPreviewImage = imageValue; - } else { - let staticPath = join(wsFolder.fsPath, staticFolder || '', imageValue); + if (staticFolder === STATIC_FOLDER_PLACEHOLDER.hexo.placeholder) { + const crntFilePath = parseWinPath(filePath); + const pathWithoutExtension = crntFilePath.replace(extname(crntFilePath), ''); + staticPath = join(pathWithoutExtension, fieldValue); + } - if (staticFolder === STATIC_FOLDER_PLACEHOLDER.hexo.placeholder) { - const crntFilePath = parseWinPath(filePath); - const pathWithoutExtension = crntFilePath.replace(extname(crntFilePath), ''); - staticPath = join(pathWithoutExtension, imageValue); - } - - const contentFolderPath = join(dirname(filePath), imageValue); + const contentFolderPath = join(dirname(filePath), fieldValue); let previewUri = null; if (await existsAsync(staticPath)) { @@ -380,7 +367,6 @@ export class PagesParser { page['fmPreviewImage'] = previewPath || ''; } } - } } } }