feat: categories accepts strings & make description optional
This commit is contained in:
parent
5ac24d0bc2
commit
70b389a4a5
4 changed files with 5 additions and 5 deletions
|
@ -2,6 +2,6 @@ import { z } from 'astro:content';
|
||||||
|
|
||||||
export const pages = z.object({
|
export const pages = z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
description: z.string(),
|
description: z.string().optional(),
|
||||||
heroImage: z.string().optional()
|
heroImage: z.string().optional()
|
||||||
});
|
});
|
|
@ -3,10 +3,10 @@ import { z, reference } from 'astro:content';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const posts = ({ image }) => z.object({
|
export const posts = ({ image }) => z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
description: z.string(),
|
description: z.string().optional(),
|
||||||
summary: z.string().optional(),
|
summary: z.string().optional(),
|
||||||
date: z.coerce.date(),
|
date: z.coerce.date(),
|
||||||
categories: z.array(z.string()).default(['uncategorized']),
|
categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']),
|
||||||
tags: z.array(z.string()).optional(),
|
tags: z.array(z.string()).optional(),
|
||||||
cover: image().optional(),
|
cover: image().optional(),
|
||||||
author: z.union([z.array(reference('authors')), reference('authors')]).optional(),
|
author: z.union([z.array(reference('authors')), reference('authors')]).optional(),
|
||||||
|
|
|
@ -29,7 +29,7 @@ async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) {
|
||||||
|
|
||||||
for (const item of sortedItems) {
|
for (const item of sortedItems) {
|
||||||
const { title, description, slug } = getMetaData(item);
|
const { title, description, slug } = getMetaData(item);
|
||||||
markdown += `\n- [${title}](${baseUrl}/blog/${slug}): ${description}`;
|
markdown += `\n- [${title}](${baseUrl}/blog/${slug}): ${description || ''}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return markdown;
|
return markdown;
|
||||||
|
|
|
@ -4,7 +4,7 @@ export async function GET() {
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts');
|
||||||
const searchIndex = posts.map(post => ({
|
const searchIndex = posts.map(post => ({
|
||||||
title: post.data.title,
|
title: post.data.title,
|
||||||
description: post.data.description,
|
description: post.data.description || '',
|
||||||
content: post.body,
|
content: post.body,
|
||||||
date: post.data.date,
|
date: post.data.date,
|
||||||
slug: post.slug
|
slug: post.slug
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue