Wowie what a gay little website for my gay little self aria.coffee
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add auto updating last modified code to blog posts

Aria 92992c61 9c6d49e1

+36 -3
+4
astro.config.mjs
··· 1 1 // @ts-check 2 2 import { defineConfig } from 'astro/config'; 3 + import { remarkModifiedTime } from './remark-modified-time.mjs'; 3 4 4 5 import preact from "@astrojs/preact"; 5 6 import tailwind from "@astrojs/tailwind"; ··· 22 23 adapter: node({ 23 24 mode: "standalone", 24 25 }), 26 + markdown: { 27 + remarkPlugins: [remarkModifiedTime], 28 + }, 25 29 });
+1
package.json
··· 17 17 "@astrojs/tailwind": "^5.1.5", 18 18 "astro": "^5.4.2", 19 19 "astro-icon": "^1.1.5", 20 + "dayjs": "^1.11.13", 20 21 "preact": "^10.26.4", 21 22 "sharp": "^0.33.5", 22 23 "tailwindcss": "^3.4.17",
+8
pnpm-lock.yaml
··· 32 32 astro-icon: 33 33 specifier: ^1.1.5 34 34 version: 1.1.5 35 + dayjs: 36 + specifier: ^1.11.13 37 + version: 1.11.13 35 38 preact: 36 39 specifier: ^10.26.4 37 40 version: 10.26.4 ··· 1088 1091 csso@5.0.5: 1089 1092 resolution: {integrity: sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==} 1090 1093 engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'} 1094 + 1095 + dayjs@1.11.13: 1096 + resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==} 1091 1097 1092 1098 debug@4.4.0: 1093 1099 resolution: {integrity: sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==} ··· 4084 4090 csso@5.0.5: 4085 4091 dependencies: 4086 4092 css-tree: 2.2.1 4093 + 4094 + dayjs@1.11.13: {} 4087 4095 4088 4096 debug@4.4.0: 4089 4097 dependencies:
+9
remark-modified-time.mjs
··· 1 + import { execSync } from "node:child_process"; 2 + 3 + export function remarkModifiedTime() { 4 + return (tree, file) => { 5 + const filepath = file.history[0]; 6 + const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); 7 + file.data.astro.frontmatter.lastModified = result.toString(); 8 + }; 9 + }
+3 -1
src/layouts/MarkdownPostLayout.astro
··· 2 2 import Partition from "../components/Partition.astro"; 3 3 import BaseLayout from "./BaseLayout.astro"; 4 4 const { frontmatter } = Astro.props; 5 + const { lastModified } = Astro.props; 5 6 --- 6 7 7 8 <BaseLayout pageTitle={frontmatter.title} description={frontmatter.description}> ··· 9 10 <p> 10 11 <h1 class="text-xl font-bold underline">{frontmatter.title}</h1> 11 12 <em>{frontmatter.description}</em><br /> 12 - <sub>Date: {frontmatter.pubDate.toLocaleDateString()}</sub> 13 + <sub>Date: {frontmatter.pubDate.toLocaleDateString()}</sub><br /> 14 + <sub>Last Modified: {lastModified}</sub> 13 15 </p> 14 16 </Partition> 15 17 <Partition>
+11 -2
src/pages/posts/[...slug].astro
··· 1 1 --- 2 2 import { getCollection, render } from "astro:content"; 3 + import dayjs from "dayjs"; 4 + import utc from "dayjs/plugin/utc"; 5 + 6 + dayjs.extend(utc); 7 + 3 8 import MarkdownPostLayout from "../../layouts/MarkdownPostLayout.astro"; 4 9 5 10 export async function getStaticPaths() { ··· 11 16 } 12 17 13 18 const { post } = Astro.props; 14 - const { Content } = await render(post); 19 + const { Content, remarkPluginFrontmatter } = await render(post); 20 + 21 + const lastModified = dayjs(remarkPluginFrontmatter.lastModified) 22 + .utc() 23 + .format("HH:mm:ss DD MMMM YYYY UTC"); 15 24 --- 16 - <MarkdownPostLayout frontmatter={post.data}> 25 + <MarkdownPostLayout frontmatter={post.data} lastModified={lastModified}> 17 26 <Content /> 18 27 </MarkdownPostLayout>