mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
Merge pull request #1007 from estruyf/revert-960-copilot/fix-958
Revert "Fix variable frontmatter error - handle both string and object formats for preview image fields"
This commit is contained in:
@@ -408,7 +408,7 @@ export class ContentType {
|
|||||||
* @param parents
|
* @param parents
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public static getFieldValue(data: any, parents: string[]): any {
|
public static getFieldValue(data: any, parents: string[]): string | string[] {
|
||||||
let fieldValue = [];
|
let fieldValue = [];
|
||||||
let crntPageData = data;
|
let crntPageData = data;
|
||||||
|
|
||||||
@@ -575,8 +575,7 @@ export class ContentType {
|
|||||||
fieldValue === null ||
|
fieldValue === null ||
|
||||||
fieldValue === undefined ||
|
fieldValue === undefined ||
|
||||||
fieldValue === '' ||
|
fieldValue === '' ||
|
||||||
(Array.isArray(fieldValue) && fieldValue.length === 0) ||
|
fieldValue.length === 0 ||
|
||||||
(typeof fieldValue === 'string' && fieldValue.length === 0) ||
|
|
||||||
fieldValue === DefaultFieldValues.faultyCustomPlaceholder
|
fieldValue === DefaultFieldValues.faultyCustomPlaceholder
|
||||||
) {
|
) {
|
||||||
emptyFields.push(fields);
|
emptyFields.push(fields);
|
||||||
|
|||||||
@@ -333,32 +333,19 @@ export class PagesParser {
|
|||||||
|
|
||||||
// Revalidate as the array could have been empty
|
// Revalidate as the array could have been empty
|
||||||
if (fieldValue) {
|
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;
|
|
||||||
} else {
|
|
||||||
// Skip processing if the value is neither a string nor an object with src
|
|
||||||
imageValue = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageValue) {
|
|
||||||
// Check if the value already starts with https - if that is the case, it is an external image
|
// Check if the value already starts with https - if that is the case, it is an external image
|
||||||
if (imageValue.startsWith('http')) {
|
if (fieldValue.startsWith('http')) {
|
||||||
page.fmPreviewImage = imageValue;
|
page.fmPreviewImage = fieldValue;
|
||||||
} else {
|
} else {
|
||||||
let staticPath = join(wsFolder.fsPath, staticFolder || '', imageValue);
|
let staticPath = join(wsFolder.fsPath, staticFolder || '', fieldValue);
|
||||||
|
|
||||||
if (staticFolder === STATIC_FOLDER_PLACEHOLDER.hexo.placeholder) {
|
if (staticFolder === STATIC_FOLDER_PLACEHOLDER.hexo.placeholder) {
|
||||||
const crntFilePath = parseWinPath(filePath);
|
const crntFilePath = parseWinPath(filePath);
|
||||||
const pathWithoutExtension = crntFilePath.replace(extname(crntFilePath), '');
|
const pathWithoutExtension = crntFilePath.replace(extname(crntFilePath), '');
|
||||||
staticPath = join(pathWithoutExtension, imageValue);
|
staticPath = join(pathWithoutExtension, fieldValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentFolderPath = join(dirname(filePath), imageValue);
|
const contentFolderPath = join(dirname(filePath), fieldValue);
|
||||||
|
|
||||||
let previewUri = null;
|
let previewUri = null;
|
||||||
if (await existsAsync(staticPath)) {
|
if (await existsAsync(staticPath)) {
|
||||||
@@ -383,7 +370,6 @@ export class PagesParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user