diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 462611c..9d4f639 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -1,35 +1,42 @@ --- -import { type CollectionEntry, getCollection } from 'astro:content'; -import Main from '@layouts/Main.astro'; +import { type CollectionEntry, getCollection } from "astro:content"; +import Main from "@layouts/Main.astro"; export async function getStaticPaths() { - const posts = await getCollection('handbook') - return posts.map((post) => ({ - params: { slug: post.slug }, - props: post, - })); + const posts = await getCollection("handbook"); + return posts.map((post) => ({ + params: { slug: post.slug }, + props: post, + })); } -type Props = CollectionEntry<'handbook'>; +type Props = CollectionEntry<"handbook">; const isProd = import.meta.env.PROD; -const {render, data} = Astro.props; -const {title, lastModified} = data; -const { Content, headings } = await render(); - -if (isProd && lastModified === undefined) { - console.log({props: Astro.props, content: Content}) -} +const { render, data } = Astro.props; +const { title } = data; +const { + Content, + headings, + remarkPluginFrontmatter: frontmatter, +} = await render(); --- -
-

{title}

- - {(lastModified ?? (isProd ? null : new Date()))!.toLocaleDateString('en-us', { - year: 'numeric', - month: 'short', - day: 'numeric', - })} -
- -
+
+

{title}

+ + { + new Date(frontmatter.lastModified).toLocaleDateString( + "en-us", + { + year: "numeric", + month: "short", + day: "numeric", + } + ) + } +
+ +
diff --git a/src/plugins/remark-last-modified.ts b/src/plugins/remark-last-modified.ts index cf2277a..13a711c 100644 --- a/src/plugins/remark-last-modified.ts +++ b/src/plugins/remark-last-modified.ts @@ -7,12 +7,14 @@ export const remarkModifiedTime: RemarkPlugins[number] = () => { const command = `git log -1 --pretty="format:%cI" "${filepath}"`; let result = execSync(command).toString().trim(); + // File is not in git yet if (result === "") { + // TODO: Add specific error handling for when the file is not in git result = new Date().toISOString(); } // @ts-ignore - file.data.astro.frontmatter.lastModified = result; + file.data.astro.frontmatter.lastModified = new Date(result); }; };