From eac69eb1a97e7f7c4d00b8ebaad16cf1965dd229 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 13 Oct 2026 22:26:27 +1100 Subject: [PATCH] feat: derive content lastmod from frontmatter dates Content pages only got lastmod from updatedAt or seo.articleModifiedTime, so pages with only a publication date, or a date in meta, had none. The resolver now reads modification dates, then publication dates, from declared fields and meta, and skips values that are not dates. contentLastmod: false turns it off. --- docs/content/1.guides/4.content.md | 19 +++++++++ docs/content/3.api/0.config.md | 6 +++ skills/nuxtjs-sitemap/SKILL.md | 1 + src/module.ts | 5 ++- src/runtime/types.ts | 11 ++++++ src/utils-internal/contentLastmod.ts | 39 +++++++++++++++++++ .../content-lastmod-off.test.ts | 22 +++++++++++ test/e2e/comark-content/default.test.ts | 8 ++++ test/e2e/content-v3/default.test.ts | 16 ++++++++ .../comark-content/content/posts/published.md | 8 ++++ .../content-v3/content/posts/dated.md | 7 ++++ .../content-v3/content/posts/published.md | 8 ++++ test/unit/content-lastmod.test.ts | 32 +++++++++++++++ 13 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 src/utils-internal/contentLastmod.ts create mode 100644 test/e2e/comark-content/content-lastmod-off.test.ts create mode 100644 test/fixtures/comark-content/content/posts/published.md create mode 100644 test/fixtures/content-v3/content/posts/dated.md create mode 100644 test/fixtures/content-v3/content/posts/published.md create mode 100644 test/unit/content-lastmod.test.ts diff --git a/docs/content/1.guides/4.content.md b/docs/content/1.guides/4.content.md index d7af758b..29d06ce1 100644 --- a/docs/content/1.guides/4.content.md +++ b/docs/content/1.guides/4.content.md @@ -250,6 +250,25 @@ content: | } ``` +### `lastmod` from frontmatter dates + +The module sets `lastmod` on a content page from its frontmatter dates: + +1. A `sitemap.lastmod` in frontmatter always wins. +2. Otherwise the modification date: `seo.articleModifiedTime`, `updatedAt`, `modifiedAt`, `dateModified` or `lastModified`. +3. Otherwise the publication date: `seo.articlePublishedTime`, `publishedAt`, `datePublished` or `date`. + +A value that is not a date is skipped. The collection schema does not need to declare these keys. + +```md +--- +publishedAt: 2025-03-01 +updatedAt: 2025-06-12 +--- +``` + +This page gets `2025-06-12`. To read no frontmatter dates, set `contentLastmod: false`. + ### Exclude from Sitemap If you'd like to exclude a page from the sitemap, you can set `sitemap: false` in the frontmatter or `robots: false` diff --git a/docs/content/3.api/0.config.md b/docs/content/3.api/0.config.md index 0e8b14ac..1184187c 100644 --- a/docs/content/3.api/0.config.md +++ b/docs/content/3.api/0.config.md @@ -51,6 +51,12 @@ This will only do anything when using multiple sitemaps. Sets the current date as the default `lastmod` for all entries that don't already have one. +## `contentLastmod: boolean`{lang="ts"} + +- Default: `true`{lang="ts"} + +Sets `lastmod` on content pages from their frontmatter dates. See [Nuxt Content](/docs/sitemap/guides/content#lastmod-from-frontmatter-dates). Set `false` to read no frontmatter dates. + ## `sitemaps: boolean | Record & { index?: (string | SitemapIndexEntry)[] }` - Default: `false` diff --git a/skills/nuxtjs-sitemap/SKILL.md b/skills/nuxtjs-sitemap/SKILL.md index c1cd84d2..4f210a00 100644 --- a/skills/nuxtjs-sitemap/SKILL.md +++ b/skills/nuxtjs-sitemap/SKILL.md @@ -28,6 +28,7 @@ If `@nuxtjs/robots` is installed, the module adds the sitemap to `robots.txt`. I - Prerendered routes are added, including routes the prerender crawler finds. - A route with the `robots: false` route rule is dropped. So is a `robots` string with `noindex` or `none`. - When a page is prerendered, `` and `