feat: add summary field in articles

This commit is contained in:
草师傅 2025-07-22 15:53:57 +08:00
parent 74a8bbc72a
commit 0eef3d8d05
Signed by: gb
GPG key ID: 43330A030E2D6478
3 changed files with 13 additions and 4 deletions

View file

@ -1,8 +1,10 @@
import { z, reference } from 'astro:content'; import { z, reference } from 'astro:content';
// @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(),
summary: z.string().optional(),
pubDate: z.coerce.date(), pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(), updatedDate: z.coerce.date().optional(),
categories: z.array(z.string()).default(['uncategorized']), categories: z.array(z.string()).default(['uncategorized']),

View file

@ -1,6 +1,7 @@
--- ---
title: 'The Art of Minimalism' title: 'The Art of Minimalism'
description: 'Thoughts on minimalism in design and code' description: 'Thoughts on minimalism in design and code'
summary: 'Exploring the principles of minimalism and its application in design and coding practices.'
pubDate: '2025-06-05' pubDate: '2025-06-05'
author: 'Wheatley' author: 'Wheatley'
tags: tags:

View file

@ -52,9 +52,10 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
<h1 class="title">{entry.data.title}</h1> <h1 class="title">{entry.data.title}</h1>
<AuthorInfo data={authorData} /> <AuthorInfo data={authorData} />
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span> <span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
{headings.length !== 0 && <TableOfContents headings={headings} />} {headings.length !== 0 && <TableOfContents headings={headings} />}
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
<div class="content"> <div class="content">
<Content /> <Content />
</div> </div>
<div class="extra-post" style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;"> <div class="extra-post" style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;">
@ -68,6 +69,11 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
</script> </script>
} }
</div> </div>
</Layout> </Layout>
<style>
p.summary {
font-style: italic;
color: var(--secondary-text-color);
margin: 1rem;
}
</style>