-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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: add <lastmod> to sitemap #9234
Conversation
Hi @pmarschik! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Thanks for submitting this @pmarschik ! Have you gotten any feedback on this PR? We use Docusaurus at Unleash and were just trying to add last mod to our docs since it is becoming increasingly important for Google. Would love to see this merged. |
@ardeche07 I've not gotten any feedback, however I've been using the changes for our published docusaurus page for some time. When I get around it, I'll update the PR with the latest changes (its not actually 170 files changed, this PR was based on docusaurus v2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @pmarschik and sorry for the late review
Your PR is not really in a state I could merge, and try to implement things that are not really needed according to Google recommendations.
It should also target main
and not docusaurus-v3
branch
Let me know if you want to give it another try, otherwise I'll create another PR.
More details on what we want to implement here:
#2604 (comment)
lastmod: | ||
routes !== undefined && options.lastmod !== false | ||
? matchRoutes(rrRoutes, routePath).find( | ||
({route}) => route?.exact === true, | ||
)?.route?.lastModified | ||
: undefined, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not ideal to use matchRoute
this way.
matchRoute
can be expensive particularly for very large sites with thousands of routes
We should create the sitemap directly from the new routes
attribute.
We have an util somewhere in core to do exactly that, and is what we use to create the routesPaths
attribute.
export function getAllFinalRoutes(routeConfig: RouteConfig[]): RouteConfig[] {
function getFinalRoutes(route: RouteConfig): RouteConfig[] {
return route.routes ? route.routes.flatMap(getFinalRoutes) : [route];
}
return routeConfig.flatMap(getFinalRoutes);
}
Honestly I'm not a fan of the routesPaths
attribute, and will likely try to remove it in favor of just routes
in the future, so I'll take this opportunity to refactor the sitemap plugin to not use routesPaths
and use routes
instead.
* truncated to date and not include the timestamp. | ||
* @see https://www.sitemaps.org/protocol.html#xmlTagDefinitions | ||
*/ | ||
lastmod: boolean | 'date'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we really need that option? 🤔
Maybe it could be useful but afaik nobody asked for this yet
/** Used for sitemap generation. Will be exposed in the lastmod tag. */ | ||
lastModified?: Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably add this to a metadata subattribute because we may assign other attributes to routes in the future and also let plugin authors assign custom ones (using an interface to allow typesafe extension through TS interface declaration merging).
These attributes should only be available on the Node side and not be part of the .docusaurus/routes.js
file generated
@@ -176,6 +176,9 @@ export default function pluginContentPages( | |||
modules: { | |||
content: source, | |||
}, | |||
// currently no way to get last modified date for pages | |||
// we would have to refactor lastUpdate from docs | |||
lastModified: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't look like necessary to add
// currently no way to get last modified date for pages | ||
// would have to refactor lastUpdate from docs | ||
lastModified: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't look like necessary to add
latestModified: _.maxBy(blogPostsOnPage, (item) => item.metadata.date) | ||
?.metadata?.date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
lastModified: _.maxBy(blogPosts, (item) => item.metadata.date) | ||
?.metadata?.date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed?
@@ -299,6 +303,7 @@ export default async function pluginContentBlog( | |||
items: blogPostItemsModule(items), | |||
metadata: aliasedSource(pageMetadataPath), | |||
}, | |||
lastModified: metadata.latestModified, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
@@ -274,6 +277,7 @@ export default async function pluginContentBlog( | |||
sidebar: aliasedSource(sidebarProp), | |||
content: metadata.source, | |||
}, | |||
lastModified: metadata.date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have metadata.lastUpdatedAt
on blog posts too now
/** Latest modified date of posts on the current page. */ | ||
readonly latestModified?: Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
Thank you for reviewing the MR @slorber.
I'm aware, this is just what I use to
I'm currently occupied with other projects and I don't know when I next have time to circle back to this. |
Thanks I'll close this one in favor of a new one, track #9954 |
Pre-flight checklist
Motivation
Add
<lastmod>
to sitemap, should fix #2604.Test Plan
Extend existing sitemap tests to expect generated lastmod date.
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/sitemap.xml
Related issues/PRs