Resolving article images

This commit is contained in:
adilallo
2025-09-29 14:33:39 -06:00
parent 8d97e647e7
commit cc1d2ec7de
13 changed files with 36 additions and 114 deletions
+25 -5
View File
@@ -39,6 +39,21 @@ export const BLOG_POST_SCHEMA = {
maxLength: 50,
},
},
thumbnail: {
type: "object",
required: false,
default: null,
properties: {
vertical: {
type: "string",
required: false,
},
horizontal: {
type: "string",
required: false,
},
},
},
};
/**
@@ -81,12 +96,12 @@ export function validateBlogPost(frontmatter) {
if (config.type === "string" && typeof frontmatter[field] === "string") {
if (config.minLength && frontmatter[field].length < config.minLength) {
errors.push(
`Field ${field} must be at least ${config.minLength} characters`,
`Field ${field} must be at least ${config.minLength} characters`
);
}
if (config.maxLength && frontmatter[field].length > config.maxLength) {
errors.push(
`Field ${field} must be no more than ${config.maxLength} characters`,
`Field ${field} must be no more than ${config.maxLength} characters`
);
}
}
@@ -105,12 +120,12 @@ export function validateBlogPost(frontmatter) {
}
if (config.items.minLength && item.length < config.items.minLength) {
errors.push(
`Item ${i} in ${field} must be at least ${config.items.minLength} characters`,
`Item ${i} in ${field} must be at least ${config.items.minLength} characters`
);
}
if (config.items.maxLength && item.length > config.items.maxLength) {
errors.push(
`Item ${i} in ${field} must be no more than ${config.items.maxLength} characters`,
`Item ${i} in ${field} must be no more than ${config.items.maxLength} characters`
);
}
}
@@ -134,7 +149,12 @@ export function sanitizeBlogPost(frontmatter) {
for (const [field, config] of Object.entries(BLOG_POST_SCHEMA)) {
if (frontmatter[field] !== undefined) {
sanitized[field] = frontmatter[field];
// Special handling for thumbnail object
if (field === "thumbnail" && typeof frontmatter[field] === "object") {
sanitized[field] = frontmatter[field];
} else {
sanitized[field] = frontmatter[field];
}
} else if (config.default !== undefined) {
sanitized[field] = config.default;
}