feat: add remark modified time plugin

This commit is contained in:
草师傅 2025-08-10 18:20:51 +08:00
parent 2c90929013
commit 87a0171185
Signed by: gb
GPG key ID: 43330A030E2D6478
2 changed files with 13 additions and 2 deletions

View file

@ -4,13 +4,14 @@ import sitemap from '@astrojs/sitemap';
import mdx from '@astrojs/mdx';
import { remarkWordCount } from './src/plugins/wordcount.js';
import { remarkWordCount } from './src/plugins/remark/wordcount.js';
import cloudflare from '@astrojs/cloudflare';
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import partytown from '@astrojs/partytown';
import {remarkModifiedTime} from "./src/plugins/remark/modified-time.mjs";
export default defineConfig({
site: 'https://terminal-blog.example.com',
@ -30,7 +31,7 @@ export default defineConfig({
theme: 'nord',
wrap: true
},
remarkPlugins: [ remarkMath, remarkWordCount ],
remarkPlugins: [ remarkMath, remarkWordCount, remarkModifiedTime ],
rehypePlugins: [ rehypeKatex ]
},

View file

@ -0,0 +1,10 @@
import { execSync } from "child_process";
import { statSync } from "node:fs";
export function remarkModifiedTime() {
return function (tree, file) {
const filepath = file.history[0];
const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`).toString() || statSync(filepath).mtime.toISOString();
file.data.astro.frontmatter.lastModified = result.toString();
};
}