Add and display last edited date field

This commit is contained in:
Maciej Pędzich 2023-05-24 10:05:25 +02:00
parent 8e178d2b5c
commit bce0a61029
3 changed files with 25 additions and 2 deletions

View File

@ -16,12 +16,20 @@
"type": "string"
},
{
"title": "Publishing date",
"title": "Date published",
"name": "pubDate",
"type": "datetime",
"default": "{{now}}",
"isPublishDate": true
},
{
"title": "Date last edited",
"name": "lastEditDate",
"type": "datetime",
"default": "{{now}}",
"isModifiedDate": true,
"required": false
},
{
"title": "Draft",
"name": "draft",

View File

@ -9,6 +9,11 @@ const blog = defineCollection({
.string()
.or(z.date())
.transform((val) => new Date(val)),
lastEditDate: z
.string()
.or(z.date())
.transform((val) => new Date(val))
.optional(),
tags: z.string().array(),
categories: z.string().array()
})

View File

@ -6,7 +6,8 @@ import FormattedDate from '../components/FormattedDate.astro';
type Props = CollectionEntry<'blog'>['data'];
const { title, description, pubDate, draft, tags, categories } = Astro.props;
const { title, description, pubDate, lastEditDate, draft, tags, categories } =
Astro.props;
const [category] = categories;
---
@ -15,6 +16,15 @@ const [category] = categories;
<h1 class="title">{title}</h1>
<div id="metadata">
<p>date published: <FormattedDate date={pubDate} /></p>
{
lastEditDate && (
<p>
<em>
date edited: <FormattedDate date={lastEditDate} />
</em>
</p>
)
}
<p>
category:
<span>