diff --git a/.github/workflows/cf-pages-deploy.yml b/.github/workflows/cf-pages-deploy.yml index 0d4187b..bf806e6 100644 --- a/.github/workflows/cf-pages-deploy.yml +++ b/.github/workflows/cf-pages-deploy.yml @@ -20,6 +20,8 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 22.x diff --git a/astro.config.mjs b/astro.config.mjs index 147b9c4..f993182 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 mdx from '@astrojs/mdx'; @@ -7,6 +8,9 @@ import tailwindcss from '@tailwindcss/vite'; // https://astro.build/config export default defineConfig({ + markdown: { + remarkPlugins: [remarkModifiedTime] + }, outDir: './build', integrations: [mdx()], vite: { diff --git a/package.json b/package.json index b1eb7c0..0178972 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@astrojs/mdx": "^4.3.13", "@tailwindcss/vite": "^4.1.18", "astro": "^5.16.8", + "dayjs": "^1.11.19", "tailwindcss": "^4.1.18" } } diff --git a/remark-modified-time.mjs b/remark-modified-time.mjs new file mode 100644 index 0000000..922fdd2 --- /dev/null +++ b/remark-modified-time.mjs @@ -0,0 +1,9 @@ +import { execSync } from "child_process"; + +export function remarkModifiedTime() { + return function (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/BaseLayout.astro b/src/layouts/BaseLayout.astro index 641fb9f..7ca5b3b 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -1,13 +1,20 @@ --- +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; import "../styles/global.css"; import Sidebar from "../components/Sidebar.astro"; import ThemeToggle from "../components/ThemeToggle.astro"; +dayjs.extend(utc) +dayjs.extend(timezone) + interface Props { title: string; description?: string; pageDescription?: string; showTitle?: boolean; + lastModified?: string; } const { @@ -15,7 +22,13 @@ const { description = "UIUC CS Wiki - A student-maintained guide to CS courses and resources", pageDescription, showTitle = false, + lastModified, } = Astro.props; + +const parsedDate = lastModified ? dayjs(lastModified) : null; +const formattedDate = parsedDate?.isValid() + ? parsedDate.tz("America/Chicago").format("MMMM DD, YYYY") + : "Unknown"; --- @@ -89,6 +102,12 @@ const { ) } + + {parsedDate && ( +

+ Last updated: {formattedDate} +

+ )} diff --git a/src/pages/classes/[subject]/[course].astro b/src/pages/classes/[subject]/[course].astro index 7e2a4af..414d19f 100644 --- a/src/pages/classes/[subject]/[course].astro +++ b/src/pages/classes/[subject]/[course].astro @@ -16,11 +16,11 @@ export async function getStaticPaths() { } const { entry } = Astro.props; -const { Content } = await entry.render(); +const { Content, remarkPluginFrontmatter } = await entry.render(); const course = entry.data; --- - +