#Automatically insert last edit date on page?
7 messages · Page 1 of 1 (latest)
Hi @strong coral. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes. Starlight has built‑in support for showing a page’s last edit date in the footer.
- Enable globally in your config
In astro.config.mjs:
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
export default defineConfig({
integrations: [
starlight({
// ...
lastUpdated: true,
}),
],
});
This turns on the Git‑based “last updated” date for all pages and shows it via the default <LastUpdated /> footer component. [LastUpdated config; Footer overrides]
- Per‑page override (optional)
In a page’s frontmatter:
---
title: Page with a custom last update date
lastUpdated: 2022-08-09
---
The lastUpdated frontmatter field (Date | boolean) overrides the global setting and can override the Git‑detected date. [lastUpdated frontmatter]
- Accessing the date in custom components (optional)
If you override components, you can read the resolved date from Astro.locals.starlightRoute.lastUpdated (a Date | undefined) and render it however you like. [Use page data; Route lastUpdated]
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@strong coral Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@dark flare I meant, is there something like a variable I can use in the page's content?
Let me check the knowledge base for you again. One moment! :books:
No, there isn’t a built‑in “last updated” variable you can drop directly into the Markdown content body itself.
Starlight’s last‑updated date is:
- Computed from Git and exposed as:
lastUpdatedin frontmatter (if you set/override it manually). [lastUpdated frontmatter]Astro.locals.starlightRoute.lastUpdatedin Astro components via route data. [Route lastUpdated; Using route data]
By default it is rendered in the footer via the <LastUpdated /> component, and you can customize how/where it appears by overriding LastUpdated or Footer (i.e. in Astro components), not from within Markdown text. [Footer overrides]
If you need to show it inside the main content area, the supported approach is:
- Override
FooterorLastUpdated.astroto move that output into the main column where you want, usingAstro.locals.starlightRoute.lastUpdated. - Or create a custom layout/component that reads
starlightRoute.lastUpdatedand renders it alongside your content.