feat: add optional 'updated' front matter for more precise updated time
This commit is contained in:
parent
65fb7cf638
commit
81ddec2e15
2 changed files with 13 additions and 12 deletions
|
@ -1,14 +1,15 @@
|
||||||
import { z, reference } from 'astro:content';
|
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().optional(),
|
description: z.string().optional(),
|
||||||
draft: z.boolean().optional().default(false),
|
draft: z.boolean().optional().default(false),
|
||||||
summary: z.string().optional(),
|
summary: z.string().optional(),
|
||||||
date: z.coerce.date(),
|
date: z.coerce.date(),
|
||||||
categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']),
|
updated: z.coerce.date().optional(),
|
||||||
tags: z.array(z.string()).optional(),
|
categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']),
|
||||||
cover: image().optional(),
|
tags: z.array(z.string()).optional(),
|
||||||
author: z.union([z.array(reference('authors')), reference('authors')]).optional(),
|
cover: image().optional(),
|
||||||
|
author: z.union([z.array(reference('authors')), reference('authors')]).optional(),
|
||||||
});
|
});
|
|
@ -37,7 +37,7 @@ const wordcount = remarkPluginFrontmatter.wordcount;
|
||||||
const lastUpdated = remarkPluginFrontmatter.lastModified;
|
const lastUpdated = remarkPluginFrontmatter.lastModified;
|
||||||
|
|
||||||
const pubDate = new Date(entry.data.date).toISOString().split('T')[0]
|
const pubDate = new Date(entry.data.date).toISOString().split('T')[0]
|
||||||
const lastUpdatedDate = new Date(lastUpdated).toISOString().split('T')[0]
|
const lastUpdatedDate = entry.data.updated ? new Date(entry.data.updated).toISOString().split('T')[0] : new Date(lastUpdated).toISOString().split('T')[0];
|
||||||
|
|
||||||
// Get author data
|
// Get author data
|
||||||
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
|
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue