mirror of
https://github.com/Xevion/utsa-handbook.git
synced 2025-12-15 12:13:43 -06:00
Last modified git-based remark plugin, site URL
This commit is contained in:
18
src/plugins/remark-last-modified.ts
Normal file
18
src/plugins/remark-last-modified.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { RemarkPlugins } from "astro";
|
||||
import { execSync } from "child_process";
|
||||
|
||||
export const remarkModifiedTime: RemarkPlugins[number] = () => {
|
||||
return function (_, file) {
|
||||
const filepath = file.history[0];
|
||||
const command = `git log -1 --pretty="format:%cI" "${filepath}"`;
|
||||
let result = execSync(command).toString();
|
||||
|
||||
// File is not in git yet
|
||||
if (result === "") {
|
||||
result = new Date().toISOString();
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
file.data.astro.frontmatter.lastModified = result;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user