#Automatically insert last edit date on page?

7 messages · Page 1 of 1 (latest)

strong coral
#

can I Automatically insert last edit date on a page when using starlight?

dark flareBOT
#

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.

  1. 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]

  1. 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]

  1. 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.

strong coral
#

@dark flare I meant, is there something like a variable I can use in the page's content?

dark flareBOT
#

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:

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:

  1. Override Footer or LastUpdated.astro to move that output into the main column where you want, using Astro.locals.starlightRoute.lastUpdated.
  2. Or create a custom layout/component that reads starlightRoute.lastUpdated and renders it alongside your content.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: