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: add <lastmod> to sitemap #9234

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ stdout: ${res.stdout}`);
silent: true,
});
shell.exec('git config user.name "Test"', {cwd: dir, silent: true});
shell.exec('git config commit.gpgsign false', {cwd: dir, silent: true});

shell.exec('git commit --allow-empty -m "First commit"', {
cwd: dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports[`paginateBlogPosts generates right pages 1`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-02T00:00:00.000Z,
"nextPage": "/blog/page/2",
"page": 1,
"permalink": "/blog",
Expand All @@ -50,6 +51,7 @@ exports[`paginateBlogPosts generates right pages 1`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-04T00:00:00.000Z,
"nextPage": "/blog/page/3",
"page": 2,
"permalink": "/blog/page/2",
Expand All @@ -66,6 +68,7 @@ exports[`paginateBlogPosts generates right pages 1`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-05T00:00:00.000Z,
"nextPage": undefined,
"page": 3,
"permalink": "/blog/page/3",
Expand All @@ -88,6 +91,7 @@ exports[`paginateBlogPosts generates right pages 2`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-02T00:00:00.000Z,
"nextPage": "/page/2",
"page": 1,
"permalink": "/",
Expand All @@ -105,6 +109,7 @@ exports[`paginateBlogPosts generates right pages 2`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-04T00:00:00.000Z,
"nextPage": "/page/3",
"page": 2,
"permalink": "/page/2",
Expand All @@ -121,6 +126,7 @@ exports[`paginateBlogPosts generates right pages 2`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-05T00:00:00.000Z,
"nextPage": undefined,
"page": 3,
"permalink": "/page/3",
Expand All @@ -146,6 +152,7 @@ exports[`paginateBlogPosts generates right pages 3`] = `
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"latestModified": 2023-08-05T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-15T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/blog/tags/tag-1",
Expand Down Expand Up @@ -47,6 +48,7 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-15T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/blog/tags/tag-2",
Expand All @@ -73,6 +75,7 @@ exports[`blog plugin works on blog tags without pagination 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-19T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/blog/tags/unlisted",
Expand Down Expand Up @@ -107,6 +110,7 @@ exports[`blog plugin works with blog tags 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-15T00:00:00.000Z,
"nextPage": "/blog/tags/tag-1/page/2",
"page": 1,
"permalink": "/blog/tags/tag-1",
Expand All @@ -123,6 +127,7 @@ exports[`blog plugin works with blog tags 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-15T00:00:00.000Z,
"nextPage": undefined,
"page": 2,
"permalink": "/blog/tags/tag-1/page/2",
Expand Down Expand Up @@ -151,6 +156,7 @@ exports[`blog plugin works with blog tags 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-15T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/blog/tags/tag-2",
Expand All @@ -177,6 +183,7 @@ exports[`blog plugin works with blog tags 1`] = `
"metadata": {
"blogDescription": "Blog",
"blogTitle": "Blog",
"latestModified": 2020-08-19T00:00:00.000Z,
"nextPage": undefined,
"page": 1,
"permalink": "/blog/tags/unlisted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('truncate', () => {
describe('paginateBlogPosts', () => {
it('generates right pages', () => {
const blogPosts = [
{id: 'post1', metadata: {}, content: 'Foo 1'},
{id: 'post2', metadata: {}, content: 'Foo 2'},
{id: 'post3', metadata: {}, content: 'Foo 3'},
{id: 'post4', metadata: {}, content: 'Foo 4'},
{id: 'post5', metadata: {}, content: 'Foo 5'},
{id: 'post1', metadata: {date: new Date(2023, 7, 1)}, content: 'Foo 1'},
{id: 'post2', metadata: {date: new Date(2023, 7, 2)}, content: 'Foo 2'},
{id: 'post3', metadata: {date: new Date(2023, 7, 3)}, content: 'Foo 3'},
{id: 'post4', metadata: {date: new Date(2023, 7, 4)}, content: 'Foo 4'},
{id: 'post5', metadata: {date: new Date(2023, 7, 5)}, content: 'Foo 5'},
] as BlogPost[];
expect(
paginateBlogPosts({
Expand Down
10 changes: 7 additions & 3 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ export function paginateBlogPosts({
}

for (let page = 0; page < numberOfPages; page += 1) {
const blogPostsOnPage = blogPosts.slice(
page * postsPerPage,
(page + 1) * postsPerPage,
);
pages.push({
items: blogPosts
.slice(page * postsPerPage, (page + 1) * postsPerPage)
.map((item) => item.id),
items: blogPostsOnPage.map((item) => item.id),
metadata: {
permalink: permalink(page),
page: page + 1,
Expand All @@ -92,6 +94,8 @@ export function paginateBlogPosts({
nextPage: page < numberOfPages - 1 ? permalink(page + 1) : undefined,
blogDescription,
blogTitle,
latestModified: _.maxBy(blogPostsOnPage, (item) => item.metadata.date)
?.metadata?.date,
Comment on lines +97 to +98
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed

},
});
}
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import path from 'path';
import _ from 'lodash';
import logger from '@docusaurus/logger';
import {
normalizeUrl,
Expand Down Expand Up @@ -233,6 +234,8 @@
modules: {
archive: aliasedSource(archiveProp),
},
lastModified: _.maxBy(blogPosts, (item) => item.metadata.date)
?.metadata?.date,
Comment on lines +237 to +238
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed?

});
}

Expand Down Expand Up @@ -274,6 +277,7 @@
sidebar: aliasedSource(sidebarProp),
content: metadata.source,
},
lastModified: metadata.date,
Copy link
Collaborator

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

});

blogItemsToMetadata[id] = metadata;
Expand All @@ -299,6 +303,7 @@
items: blogPostItemsModule(items),
metadata: aliasedSource(pageMetadataPath),
},
lastModified: metadata.latestModified,
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed

});
}),
);
Expand All @@ -321,6 +326,10 @@
sidebar: aliasedSource(sidebarProp),
tags: aliasedSource(tagsPropPath),
},
lastModified: _.maxBy(
_.flatMap(blogTags, (item) => item.pages),

Check failure on line 330 in packages/docusaurus-plugin-content-blog/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

'_.flatMap' is restricted from being used. Use Array#flatMap instead
(item) => item.metadata?.latestModified,
)?.metadata?.latestModified,
});
}

Expand Down Expand Up @@ -348,6 +357,7 @@
tag: aliasedSource(tagPropPath),
listMetadata: aliasedSource(listMetadataPath),
},
lastModified: metadata.latestModified,
});
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
readonly totalCount: number;
/** Total number of list pages. */
readonly totalPages: number;
/** Latest modified date of posts on the current page. */
readonly latestModified?: Date;
Comment on lines +502 to +503
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed

};

export type BlogPaginated = {
Expand Down
Loading
Loading