diff --git a/astro.config.mjs b/astro.config.mjs
index aa51592..ea6b341 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -1,5 +1,6 @@
// @ts-check
import { defineConfig } from 'astro/config';
+import { remarkModifiedTime } from './remark-modified-time.mjs';
import preact from "@astrojs/preact";
import tailwind from "@astrojs/tailwind";
@@ -22,4 +23,7 @@ export default defineConfig({
adapter: node({
mode: "standalone",
}),
+ markdown: {
+ remarkPlugins: [remarkModifiedTime],
+ },
});
\ No newline at end of file
diff --git a/package.json b/package.json
index 6ada479..c1927bc 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"@astrojs/tailwind": "^5.1.5",
"astro": "^5.4.2",
"astro-icon": "^1.1.5",
+ "dayjs": "^1.11.13",
"preact": "^10.26.4",
"sharp": "^0.33.5",
"tailwindcss": "^3.4.17",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1c98159..4536bd5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -32,6 +32,9 @@ importers:
astro-icon:
specifier: ^1.1.5
version: 1.1.5
+ dayjs:
+ specifier: ^1.11.13
+ version: 1.11.13
preact:
specifier: ^10.26.4
version: 10.26.4
@@ -1089,6 +1092,9 @@ packages:
resolution: {integrity: sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==}
engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'}
+ dayjs@1.11.13:
+ resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
+
debug@4.4.0:
resolution: {integrity: sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==}
engines: {node: '>=6.0'}
@@ -4085,6 +4091,8 @@ snapshots:
dependencies:
css-tree: 2.2.1
+ dayjs@1.11.13: {}
+
debug@4.4.0:
dependencies:
ms: 2.1.3
diff --git a/remark-modified-time.mjs b/remark-modified-time.mjs
new file mode 100644
index 0000000..b0793c7
--- /dev/null
+++ b/remark-modified-time.mjs
@@ -0,0 +1,9 @@
+import { execSync } from "node:child_process";
+
+export function remarkModifiedTime() {
+ return (tree, file) => {
+ const filepath = file.history[0];
+ const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`);
+ file.data.astro.frontmatter.lastModified = result.toString();
+ };
+}
\ No newline at end of file
diff --git a/src/layouts/MarkdownPostLayout.astro b/src/layouts/MarkdownPostLayout.astro
index 6bd38b6..a003ba5 100644
--- a/src/layouts/MarkdownPostLayout.astro
+++ b/src/layouts/MarkdownPostLayout.astro
@@ -2,6 +2,7 @@
import Partition from "../components/Partition.astro";
import BaseLayout from "./BaseLayout.astro";
const { frontmatter } = Astro.props;
+const { lastModified } = Astro.props;
---
{frontmatter.title}
{frontmatter.description}
- Date: {frontmatter.pubDate.toLocaleDateString()}
+ Date: {frontmatter.pubDate.toLocaleDateString()}
+ Last Modified: {lastModified}