mirror of
https://github.com/Xevion/utsa-handbook.git
synced 2025-12-06 07:16:47 -06:00
Fix remark last modified metadata handling
This commit is contained in:
@@ -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();
|
||||
---
|
||||
|
||||
<Main {headings} { ...data}>
|
||||
<h2 class="text-2xl font-semibold mb-2">{title}</h2>
|
||||
<!-- lastModified can be undefined in some rare circumstances (usually development only), this might fail in production if something went wrong. -->
|
||||
<span>{(lastModified ?? (isProd ? null : new Date()))!.toLocaleDateString('en-us', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})}</span>
|
||||
<div class="prose xl:prose-lg prose-zinc dark:prose-invert">
|
||||
<Content />
|
||||
</div>
|
||||
<Main {headings} {...data}>
|
||||
<h2 class="text-2xl font-semibold mb-2">{title}</h2>
|
||||
<!-- lastModified can be undefined in some rare circumstances (usually development only), this might fail in production if something went wrong. -->
|
||||
<span
|
||||
>{
|
||||
new Date(frontmatter.lastModified).toLocaleDateString(
|
||||
"en-us",
|
||||
{
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
}
|
||||
)
|
||||
}</span
|
||||
>
|
||||
<div class="prose xl:prose-lg prose-zinc dark:prose-invert">
|
||||
<Content />
|
||||
</div>
|
||||
</Main>
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user