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): add blog pageBasePath plugin option #9838

Merged
merged 8 commits into from
Feb 13, 2024

Conversation

ilg-ul
Copy link
Contributor

@ilg-ul ilg-ul commented Feb 8, 2024

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

In Docusaurus, the URL parts used to compose the paths are configurable via options like routeBasePath, tagsBasePath, etc, but in the path used for multi-page lists, a part of the URL is hard-coded as page.

Test Plan

TBD

Test links

TBD

Related issues/PRs

fix #9828

@ilg-ul ilg-ul requested a review from slorber as a code owner February 8, 2024 20:58
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 8, 2024
Copy link

netlify bot commented Feb 8, 2024

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit dd81393
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65c87f2f8399db0008baa206
😎 Deploy Preview https://deploy-preview-9838--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 8, 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 🟠 84 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 74 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 70 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 63 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 69 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 78 🟢 100 🟢 100 🟢 90 🟠 88 Report

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Feb 9, 2024

I did not find a way to test xxxBasePath definitions, to inspire from. :-(

Please advise on how to proceed.

@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 Feb 9, 2024
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.

LGTM, although tests are failing and should be updated.

You can test your feature in this existing test suite.

Note that it would be nice to also ensure that the code is not sensitive to the presence/absence of a path leading/trailing slash here

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'},
    ] as BlogPost[];
    expect(
      paginateBlogPosts({
        blogPosts,
        basePageUrl: '/blog',
        blogTitle: 'Blog Title',
        blogDescription: 'Blog Description',
        postsPerPageOption: 2,
      }),
    ).toMatchSnapshot();
    expect(
      paginateBlogPosts({
        blogPosts,
        basePageUrl: '/',
        blogTitle: 'Blog Title',
        blogDescription: 'Blog Description',
        postsPerPageOption: 2,
      }),
    ).toMatchSnapshot();
    expect(
      paginateBlogPosts({
        blogPosts,
        basePageUrl: '/',
        blogTitle: 'Blog Title',
        blogDescription: 'Blog Description',
        postsPerPageOption: 10,
      }),
    ).toMatchSnapshot();
  });
});

It currently fails because you didn't add the extra method param to that test suite.


Not relate to this PR but I noticed a useless param returned in the loaded content, I'd appreciate if you could remove it: blogTagsPaginated: []:
https://github.com/cronica-it/docusaurus-fork/blob/issue-9828/packages/docusaurus-plugin-content-blog/src/index.ts#L125

packages/docusaurus-plugin-content-blog/src/blogUtils.ts Outdated Show resolved Hide resolved
website/docs/api/plugins/plugin-content-blog.mdx Outdated Show resolved Hide resolved
@ilg-ul
Copy link
Contributor Author

ilg-ul commented Feb 9, 2024

I guess I addressed all requested changes and the tests passed.

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.

LGTM 👍 I would add an extra test to paginateBlogPosts to actually cover this new feature

@slorber
Copy link
Collaborator

slorber commented Feb 13, 2024

Thanks 👍 LGTM

@slorber slorber changed the title feat(blog): add pageBasePath feat(blog): add pageBasePath option Feb 13, 2024
@slorber slorber changed the title feat(blog): add pageBasePath option feat(blog): add blog pageBasePath plugin option Feb 13, 2024
@slorber slorber merged commit 70ba9d2 into facebook:main Feb 13, 2024
31 checks passed
@ilg-ul
Copy link
Contributor Author

ilg-ul commented Feb 13, 2024

Thank you, Sébastien!

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 pageBasePath to blog plugin configuration
3 participants