Add auto updating last modified code to blog posts
This commit is contained in:
parent
9c6d49e14f
commit
92992c6142
6 changed files with 36 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
import Partition from "../components/Partition.astro";
|
||||
import BaseLayout from "./BaseLayout.astro";
|
||||
const { frontmatter } = Astro.props;
|
||||
const { lastModified } = Astro.props;
|
||||
---
|
||||
|
||||
<BaseLayout pageTitle={frontmatter.title} description={frontmatter.description}>
|
||||
|
@ -9,7 +10,8 @@ const { frontmatter } = Astro.props;
|
|||
<p>
|
||||
<h1 class="text-xl font-bold underline">{frontmatter.title}</h1>
|
||||
<em>{frontmatter.description}</em><br />
|
||||
<sub>Date: {frontmatter.pubDate.toLocaleDateString()}</sub>
|
||||
<sub>Date: {frontmatter.pubDate.toLocaleDateString()}</sub><br />
|
||||
<sub>Last Modified: {lastModified}</sub>
|
||||
</p>
|
||||
</Partition>
|
||||
<Partition>
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
---
|
||||
import { getCollection, render } from "astro:content";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
import MarkdownPostLayout from "../../layouts/MarkdownPostLayout.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
|
@ -11,8 +16,12 @@ export async function getStaticPaths() {
|
|||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
const { Content } = await render(post);
|
||||
const { Content, remarkPluginFrontmatter } = await render(post);
|
||||
|
||||
const lastModified = dayjs(remarkPluginFrontmatter.lastModified)
|
||||
.utc()
|
||||
.format("HH:mm:ss DD MMMM YYYY UTC");
|
||||
---
|
||||
<MarkdownPostLayout frontmatter={post.data}>
|
||||
<MarkdownPostLayout frontmatter={post.data} lastModified={lastModified}>
|
||||
<Content />
|
||||
</MarkdownPostLayout>
|
Loading…
Add table
Add a link
Reference in a new issue