feat: add remark modified time plugin
This commit is contained in:
parent
2c90929013
commit
87a0171185
2 changed files with 13 additions and 2 deletions
|
@ -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 ]
|
||||
},
|
||||
|
||||
|
|
10
src/plugins/remark/modified-time.mjs
Normal file
10
src/plugins/remark/modified-time.mjs
Normal 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();
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue