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(blog): allow processing blog posts through a processBlogPosts function #9886

Merged
merged 18 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`blog plugin process blog posts load content 1`] = `
[
{
"content": "2031",
"id": "/date/2031",
"metadata": {
"authors": [],
"date": 2031-01-01T00:00:00.000Z,
"description": "2031",
"editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md",
"formattedDate": "January 1, 2031",
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
"frontMatter": {
"date": 2031-01-01T00:00:00.000Z,
"slug": "/date/2031",
"title": "2031",
"unlisted": true,
},
"hasTruncateMarker": false,
"nextItem": {
"permalink": "/blog/date/2030",
"title": "2030",
},
"permalink": "/blog/date/2031",
"readingTime": 0.005,
"source": "@site/blog/date-2031-unlisted.md",
"tags": [],
"title": "2031",
"unlisted": false,
},
},
{
"content": "2030",
"id": "/date/2030",
"metadata": {
"authors": [],
"date": 2030-01-01T00:00:00.000Z,
"description": "2030",
"editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md",
"formattedDate": "January 1, 2030",
"frontMatter": {
"date": 2030-01-01T00:00:00.000Z,
"slug": "/date/2030",
"title": "2030",
},
"hasTruncateMarker": false,
"permalink": "/blog/date/2030",
"prevItem": {
"permalink": "/blog/date/2031",
"title": "2031",
},
"readingTime": 0.005,
"source": "@site/blog/date-2030.md",
"tags": [],
"title": "2030",
"unlisted": false,
},
},
]
`;

exports[`blog plugin works on blog tags without pagination 1`] = `
{
"/blog/tags/tag-1": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
sortPosts: 'ascending',
});
expect(normalOrder.reverse().map((x) => x.metadata.date)).toEqual(
reversedOrder.map((x) => x.metadata.date),

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

View workflow job for this annotation

GitHub Actions / Windows Tests (18.0)

blog plugin › process blog posts load content

expect(received).toMatchSnapshot() Snapshot name: `blog plugin process blog posts load content 1` - Snapshot - 2 + Received + 0 @@ -5,11 +5,10 @@ "metadata": { "authors": [], "date": 2031-01-01T00:00:00.000Z, "description": "2031", "editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md", - "formattedDate": "January 1, 2031", "frontMatter": { "date": 2031-01-01T00:00:00.000Z, "slug": "/date/2031", "title": "2031", "unlisted": true, @@ -33,11 +32,10 @@ "metadata": { "authors": [], "date": 2030-01-01T00:00:00.000Z, "description": "2030", "editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md", - "formattedDate": "January 1, 2030", "frontMatter": { "date": 2030-01-01T00:00:00.000Z, "slug": "/date/2030", "title": "2030", }, at Object.toMatchSnapshot (packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts:514:32)

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

View workflow job for this annotation

GitHub Actions / Windows Tests (18)

blog plugin › process blog posts load content

expect(received).toMatchSnapshot() Snapshot name: `blog plugin process blog posts load content 1` - Snapshot - 2 + Received + 0 @@ -5,11 +5,10 @@ "metadata": { "authors": [], "date": 2031-01-01T00:00:00.000Z, "description": "2031", "editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md", - "formattedDate": "January 1, 2031", "frontMatter": { "date": 2031-01-01T00:00:00.000Z, "slug": "/date/2031", "title": "2031", "unlisted": true, @@ -33,11 +32,10 @@ "metadata": { "authors": [], "date": 2030-01-01T00:00:00.000Z, "description": "2030", "editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md", - "formattedDate": "January 1, 2030", "frontMatter": { "date": 2030-01-01T00:00:00.000Z, "slug": "/date/2030", "title": "2030", }, at Object.toMatchSnapshot (packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts:514:32)

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

View workflow job for this annotation

GitHub Actions / Tests (18.0)

blog plugin › process blog posts load content

expect(received).toMatchSnapshot() Snapshot name: `blog plugin process blog posts load content 1` - Snapshot - 2 + Received + 0 @@ -5,11 +5,10 @@ "metadata": { "authors": [], "date": 2031-01-01T00:00:00.000Z, "description": "2031", "editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md", - "formattedDate": "January 1, 2031", "frontMatter": { "date": 2031-01-01T00:00:00.000Z, "slug": "/date/2031", "title": "2031", "unlisted": true, @@ -33,11 +32,10 @@ "metadata": { "authors": [], "date": 2030-01-01T00:00:00.000Z, "description": "2030", "editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md", - "formattedDate": "January 1, 2030", "frontMatter": { "date": 2030-01-01T00:00:00.000Z, "slug": "/date/2030", "title": "2030", }, at Object.toMatchSnapshot (packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts:514:32)

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

View workflow job for this annotation

GitHub Actions / Tests (18)

blog plugin › process blog posts load content

expect(received).toMatchSnapshot() Snapshot name: `blog plugin process blog posts load content 1` - Snapshot - 2 + Received + 0 @@ -5,11 +5,10 @@ "metadata": { "authors": [], "date": 2031-01-01T00:00:00.000Z, "description": "2031", "editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md", - "formattedDate": "January 1, 2031", "frontMatter": { "date": 2031-01-01T00:00:00.000Z, "slug": "/date/2031", "title": "2031", "unlisted": true, @@ -33,11 +32,10 @@ "metadata": { "authors": [], "date": 2030-01-01T00:00:00.000Z, "description": "2030", "editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md", - "formattedDate": "January 1, 2030", "frontMatter": { "date": 2030-01-01T00:00:00.000Z, "slug": "/date/2030", "title": "2030", }, at Object.toMatchSnapshot (packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts:514:32)

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

View workflow job for this annotation

GitHub Actions / Tests (20)

blog plugin › process blog posts load content

expect(received).toMatchSnapshot() Snapshot name: `blog plugin process blog posts load content 1` - Snapshot - 2 + Received + 0 @@ -5,11 +5,10 @@ "metadata": { "authors": [], "date": 2031-01-01T00:00:00.000Z, "description": "2031", "editUrl": "https://baseEditUrl.com/edit/blog/date-2031-unlisted.md", - "formattedDate": "January 1, 2031", "frontMatter": { "date": 2031-01-01T00:00:00.000Z, "slug": "/date/2031", "title": "2031", "unlisted": true, @@ -33,11 +32,10 @@ "metadata": { "authors": [], "date": 2030-01-01T00:00:00.000Z, "description": "2030", "editUrl": "https://baseEditUrl.com/edit/blog/date-2030.md", - "formattedDate": "January 1, 2030", "frontMatter": { "date": 2030-01-01T00:00:00.000Z, "slug": "/date/2030", "title": "2030", }, at Object.toMatchSnapshot (packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts:514:32)
);
});

Expand Down Expand Up @@ -541,4 +541,19 @@

expect(blogTags).toMatchSnapshot();
});

it('process blog posts load content', async () => {
const siteDir = path.join(
__dirname,
'__fixtures__',
'website-blog-with-dates',
);
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
const processedBlogPosts = await getBlogPosts(siteDir, {
postsPerPage: 2,
processBlogPosts: async ({blogPosts}) =>
blogPosts.filter((blog) => blog.metadata.date.getFullYear() > 2029),
});

expect(processedBlogPosts).toMatchSnapshot();
});
});