Add blog CMS with tracked public posts
This commit is contained in:
@@ -111,3 +111,31 @@ export function parseAffiliate(body: Record<string, unknown>) {
|
||||
sortIndex: int(body.sortIndex),
|
||||
};
|
||||
}
|
||||
|
||||
function slug(value: unknown): string {
|
||||
const normalized = str(value, "slug")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
|
||||
if (!normalized) {
|
||||
throw new ValidationError('"slug" is invalid');
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function parseBlogPost(body: Record<string, unknown>) {
|
||||
const isPublished = bool(body.isPublished);
|
||||
const publishedAt = optDate(body.publishedAt);
|
||||
|
||||
return {
|
||||
title: str(body.title, "title"),
|
||||
slug: slug(body.slug),
|
||||
excerpt: str(body.excerpt, "excerpt"),
|
||||
coverImageUrl: optStr(body.coverImageUrl),
|
||||
content: str(body.content, "content"),
|
||||
isPublished,
|
||||
publishedAt: isPublished ? publishedAt ?? new Date() : publishedAt,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user