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

Conversation

OzakIOne
Copy link
Contributor

@OzakIOne OzakIOne commented Feb 23, 2024

Motivation

This new option processBlogPost allow the user to modify BlogPost array used in archive page and blog page.

For example the user can filter to only list blogs that were created after year 2020 or sort BlogPost by alphabetical order.

#9840 (review)

blog: {
  path: 'blog',
  processBlogPosts: async ({blogPosts}) =>
      blogPosts.filter(
        (blog) => blog.metadata.date.getFullYear() > 2020,
      ),
}
blog: {
  path: 'blog',
  processBlogPosts: async ({blogPosts}) =>
      blogPosts.sort((a, b) =>
        a.metadata.title.localeCompare(b.metadata.title),
      ),
}

Test Plan

yarn jest docusaurus-plugin-content-blog --watch

Test links

Blog page

Archive page

processBlogPosts documentation

Related issues/PRs

Supersed #9840

Fix #9831

Fix #9827

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 23, 2024
Copy link

netlify bot commented Feb 23, 2024

[V2]

Name Link
🔨 Latest commit 2bc22d3
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65e7453629430800080d1663
😎 Deploy Preview https://deploy-preview-9886--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 Feb 23, 2024

⚡️ Lighthouse report for the deploy preview of this PR

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

Copy link

github-actions bot commented Feb 23, 2024

Size Change: 0 B

Total Size: 992 kB

ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 75.4 kB
website/build/assets/css/styles.********.css 114 kB
website/build/assets/js/main.********.js 765 kB
website/build/index.html 37.9 kB

compressed-size-action

Copy link
Collaborator

@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.

Almost looks good

That would also be nice to have an extra test in index.test.ts to cover the fact that the processBlogPost option has an impact on the plugin loadContent result.

For example, take a simple site with 10 blog posts, page size = 3, and provide a processBlogPosts that only take the 4 first blog posts in the list: the resulting number of pages should be 2 instead of 4.

This kind of test ensures the plugin works overall, and covers the fact that applyProcessBlogPosts is called before blogPosts.filter(shouldBeListed), which is important otherwise we would have a bug.

@OzakIOne OzakIOne changed the title feat(blog): allow process blog posts through a options.processBlogPost function feat(blog): allow process blog posts through a processBlogPosts function Mar 4, 2024
@OzakIOne OzakIOne marked this pull request as ready for review March 4, 2024 17:47
@OzakIOne OzakIOne requested a review from Josh-Cena as a code owner March 4, 2024 17:47
Copy link
Collaborator

@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.

Almost good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Argos Add this label to run UI visual regression tests. See argos.yml GH action. 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
3 participants