Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sitemap): add support for "lastmod" #9954

Merged
merged 18 commits into from Mar 20, 2024
Merged

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Mar 15, 2024

Motivation

Fix #2604

Add new sitemap options:

{
  lastmod: null | 'date' | 'datetime'
  priority: null,
  changefreq: null,
}
  • Add a new sitemap option lastmod that permits to output <lastmod> tags in the sitemap, formatted as YYYY-MM-DD date, or ISO datetime
  • Allow to disable useless <changefreq> and <priority> sitemap tags (Google doesn't use them) with null values

Important notes:

  • lastmod only works for routes backed and requires plugin authors to add new route metadata when calling addRoute()
  • All our official content plugins provide this route metadata
  • If plugins allow to provide a last updated time as front matter, then it's possible for the sitemap plugin to use this explicit date in priority. Otherwise, a timestamp will be inferred from the Git history of the content source file.
  • We are able to output a <lastmod> tag for React page components as well. However it will only use the React page source Git history, and will not check history of its dependencies.
  • Not all routes will have a <lastmod> tag. If a third-party plugin does not provide the new metadata, the sitemap can't infer a proper value. According to Google recommendations, it's only relevant to use <lastmod> tags for routes backed by content, and not routes aggregating multiple documents (tags, blog pagination, blog archive, doc autogenerated index...)

Test Plan

Unit tests + dogfood on our website

Test links

Related issues/PRs

Supersed PR #9234

@slorber slorber added pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus labels Mar 15, 2024
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 15, 2024
@slorber slorber mentioned this pull request Mar 15, 2024
3 tasks
@slorber slorber changed the title feat(sitemap): feat(sitemap): add support for "lastmod" Mar 15, 2024
Copy link

netlify bot commented Mar 15, 2024

[V2]

Name Link
🔨 Latest commit d92d80d
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65fabb7a60eb5c00078573c5
😎 Deploy Preview https://deploy-preview-9954--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 15, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🔴 46 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 59 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 69 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 59 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 71 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report

Copy link

github-actions bot commented Mar 15, 2024

Size Change: +45 B (0%)

Total Size: 992 kB

Filename Size Change
website/build/assets/js/main.********.js 765 kB +45 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 75.4 kB
website/build/assets/css/styles.********.css 114 kB
website/build/index.html 37.9 kB

compressed-size-action

@slorber slorber marked this pull request as ready for review March 19, 2024 16:02
@slorber slorber requested a review from Josh-Cena as a code owner March 19, 2024 16:02
@slorber slorber mentioned this pull request Mar 19, 2024
Copy link
Contributor

@johnnyreilly johnnyreilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent work; I like that you're looking to make the default sitemap include lastmod by default with Docusaurus v4

Copy link
Collaborator Author

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Thanks for the review 🙏

packages/docusaurus-plugin-sitemap/src/types.ts Outdated Show resolved Hide resolved
@slorber slorber merged commit 9017fb9 into main Mar 20, 2024
31 checks passed
@slorber slorber deleted the slorber/sitemap-lastmod branch March 20, 2024 10:47
@razzeee
Copy link
Contributor

razzeee commented Apr 1, 2024

Is it expected, that lastmod is always today? (might be date of last deploy)
For every page?

See https://docs.flathub.org/sitemap.xml
Code is here https://github.com/flathub-infra/documentation

@slorber
Copy link
Collaborator Author

slorber commented Apr 2, 2024

@razzeee you need to configure your CI to fetch the full git history.
I may have missed to mention that in the plugin docs, but it should be there in docs/blog docs.

@johnnyreilly
Copy link
Contributor

You may need:

      - name: Checkout 📥
        uses: actions/checkout@v4
        with:
          # Number of commits to fetch. 0 indicates all history for all branches and tags.
          fetch-depth: 0
          submodules: true

https://github.com/johnnyreilly/blog.johnnyreilly.com/blob/2a4665f3accd44f9199b8232310368dedac37f19/.github/workflows/build-and-deploy-static-web-app.yml#L33C1-L38C27

@razzeee
Copy link
Contributor

razzeee commented Apr 2, 2024

Thanks, working now

@pmarschik
Copy link

pmarschik commented Apr 3, 2024

I've now got around to trying the released version.
On our CI it works as expected, however locally I have the git config log.showSignature = true which causes npm docusaurus build to fail with:

[ERROR] Loading of version failed for version current

[ERROR] Error: Unable to build website for locale en.

[...]

Error: Can't process doc metadata for doc at path path=/Users/<redacted> in version name=current

[cause]: Error: An error occurred when trying to get the last update date
    at getGitLastUpdate (/Users/<redacted>/node_modules/.pnpm/@docusaurus+utils@3.2.0_@docusaurus+types@3.2.0_@swc+core@1.4.11_esbuild@0.17.19/node_modules/@docusaurus/utils/lib/lastUpdateUtils.js:43:19)
        
[cause]: Error: Failed to retrieve the git history for file "/Users/<redacted>/file.mdx" with unexpected output: Good "git" signature for somebody@example.org with ED25519-SK key SHA256:<somekey>
  <sometimestamp>,<some name>
      at getFileCommitDate (/Users/<redacted>/node_modules/.pnpm/@docusaurus+utils@3.2.0_@docusaurus+types@3.2.0_@swc+core@1.4.11_esbuild@0.17.19/node_modules/@docusaurus/utils/lib/gitUtils.js:63:15)

To make the logic in packages/docusaurus-utils/src/gitUtils.ts more robust we could:

  • Set -c log.showSignature=false on the CLI. But this needs to be adapted for any new setting that modifies the output.
  • Mark the output that we want to parse: set --format=COMMIT-TIMESTAMP:%ct${includeAuthor ? ',COMMIT-AUTHOR:%an' : ''} and extend the regex with the tags and allow multiline matches.

@slorber
Copy link
Collaborator Author

slorber commented Apr 5, 2024

Thanks @pmarschik , I adopted both solutions at once in #10022

and extend the regex with the tags and allow multiline matches.

Not sure what you mean here

@pmarschik
Copy link

Thanks @pmarschik , I adopted both solutions at once in #10022

and extend the regex with the tags and allow multiline matches.

Not sure what you mean here

@slorber Thanks for the quick fix.

I meant exactly what you merged in #10022. Except with multiline I meant the RegExp could be /^RESULT:(?<timestamp>\d+),(?<author>.+)$/m instead of /(?:^|\n)RESULT:(?<timestamp>\d+),(?<author>.+)(?:$|\n)/

@slorber
Copy link
Collaborator Author

slorber commented Apr 5, 2024

ah I see thanks, just a different way to express the same thing I guess (and yours look better 😅 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lastmod to sitemap
5 participants