diff --git a/.github/workflows/argos.yml b/.github/workflows/argos.yml index 2e5d8d9339..f381f3c242 100644 --- a/.github/workflows/argos.yml +++ b/.github/workflows/argos.yml @@ -27,10 +27,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository code - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/build-blog-only.yml b/.github/workflows/build-blog-only.yml index 0e467bdd2f..18f6777d7c 100644 --- a/.github/workflows/build-blog-only.yml +++ b/.github/workflows/build-blog-only.yml @@ -22,9 +22,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/build-hash-router.yml b/.github/workflows/build-hash-router.yml index 1867f0b162..1c74352a1a 100644 --- a/.github/workflows/build-hash-router.yml +++ b/.github/workflows/build-hash-router.yml @@ -25,9 +25,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn @@ -44,20 +44,20 @@ jobs: # BASE_URL: '/docusaurus/' # hash router + - name: Upload Website artifact - uses: actions/upload-artifact@v5 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: website-hash-router-archive path: website/build #- name: Upload Website Pages artifact - # uses: actions/upload-pages-artifact@v3 + # uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 # with: # path: website/build # Deploy to https://facebook.github.io/docusaurus/ - name: Deploy to GitHub Pages if: ${{ github.event_name != 'pull_request' && github.ref_name == 'main' }} - uses: peaceiris/actions-gh-pages@v4 + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: website/build @@ -81,4 +81,4 @@ jobs: # steps: # - name: Deploy to GitHub Pages # id: deployment - # uses: actions/deploy-pages@v4 + # uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 diff --git a/.github/workflows/build-perf.yml b/.github/workflows/build-perf.yml index 3b30568b79..c1c7b5d7a6 100644 --- a/.github/workflows/build-perf.yml +++ b/.github/workflows/build-perf.yml @@ -41,14 +41,14 @@ jobs: DOCUSAURUS_INFRA: ['SLOWER', 'FASTER'] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn - name: Track build size changes - uses: preactjs/compressed-size-action@946a292cd35bd1088e0d7eb92b69d1a8d5b5d76a # v2 + uses: preactjs/compressed-size-action@8518045ed95e94e971b83333085e1cb99aa18aa8 # v2.9.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} build-script: build:website:fast @@ -74,9 +74,9 @@ jobs: DOCUSAURUS_INFRA: ['SLOWER', 'FASTER'] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/canary-release.yml b/.github/workflows/canary-release.yml index 0fd54f420e..cbcf9e877a 100644 --- a/.github/workflows/canary-release.yml +++ b/.github/workflows/canary-release.yml @@ -20,11 +20,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: fetch-depth: 0 # Needed to get the commit number with "git rev-list --count HEAD" - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ffd4b4ebab..e544c63f62 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Initialize CodeQL uses: github/codeql-action/init@4e94bd11f71e507f7f87df81788dff88d1dacbfb # 4.31.0 diff --git a/.github/workflows/continuous-releases.yml b/.github/workflows/continuous-releases.yml index 8981874054..2b26a9e81f 100644 --- a/.github/workflows/continuous-releases.yml +++ b/.github/workflows/continuous-releases.yml @@ -18,10 +18,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index dc0e454dc1..813363d2fd 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -13,6 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Dependency Review uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # 4.8.2 diff --git a/.github/workflows/lighthouse-report.yml b/.github/workflows/lighthouse-report.yml index 0e2748b5db..cc6fc8c1eb 100644 --- a/.github/workflows/lighthouse-report.yml +++ b/.github/workflows/lighthouse-report.yml @@ -21,10 +21,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/lint-autofix.yml b/.github/workflows/lint-autofix.yml index 47a7eee75d..a1be962fd3 100644 --- a/.github/workflows/lint-autofix.yml +++ b/.github/workflows/lint-autofix.yml @@ -19,7 +19,7 @@ jobs: contents: write steps: - - uses: actions/checkout@v6.0.0 + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} @@ -42,6 +42,6 @@ jobs: - name: Print Diff run: git diff - - uses: stefanzweifel/git-auto-commit-action@v7 + - uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0 with: commit_message: 'refactor: apply lint autofix' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d292e59ab9..bcba72d055 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,9 +20,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/showcase-test.yml b/.github/workflows/showcase-test.yml index 37f61e9a2c..6b8fd4d16b 100644 --- a/.github/workflows/showcase-test.yml +++ b/.github/workflows/showcase-test.yml @@ -22,9 +22,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 3b4d164749..06c703a756 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -41,9 +41,9 @@ jobs: node: ['20.0', '20', '22', '24', '25.1'] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: ${{ matrix.node }} cache: yarn @@ -78,9 +78,9 @@ jobs: runs-on: windows-8-core steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js LTS - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn @@ -109,7 +109,7 @@ jobs: DOCUSAURUS_PERF_LOGGER: 'true' working-directory: test-website-in-workspace - name: Upload Website artifact - uses: actions/upload-artifact@v5 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: website-e2e-windows path: test-website-in-workspace/build @@ -124,9 +124,9 @@ jobs: variant: [-s, -st] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js LTS - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn @@ -193,9 +193,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js LTS - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn @@ -233,9 +233,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js LTS - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-swizzle.yml b/.github/workflows/tests-swizzle.yml index fe9e595af3..bd52ac93a4 100644 --- a/.github/workflows/tests-swizzle.yml +++ b/.github/workflows/tests-swizzle.yml @@ -26,9 +26,9 @@ jobs: variant: ['js', 'ts'] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Node LTS - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index 37981c39c6..c1feb517e8 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -32,9 +32,9 @@ jobs: - name: Support longpaths run: git config --system core.longpaths true - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: ${{ matrix.node }} cache: yarn diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bc4f4ce8ca..9a71d589f8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,9 +30,9 @@ jobs: node: ['20.0', '20', '22', '24', '25.1'] steps: - name: Checkout - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 with: node-version: ${{ matrix.node }} cache: yarn diff --git a/packages/create-docusaurus/src/index.ts b/packages/create-docusaurus/src/index.ts index fadb644680..ae9180746b 100755 --- a/packages/create-docusaurus/src/index.ts +++ b/packages/create-docusaurus/src/index.ts @@ -273,7 +273,10 @@ async function getSiteName( return 'A website name is required.'; } const dest = path.resolve(rootDir, siteName); - if (await fs.pathExists(dest)) { + if (siteName === '.' && (await fs.readdir(dest)).length > 0) { + return logger.interpolate`Directory not empty at path=${dest}!`; + } + if (siteName !== '.' && (await fs.pathExists(dest))) { return logger.interpolate`Directory already exists at path=${dest}!`; } return true; diff --git a/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx b/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx index 00263ad590..5d8b30a0cc 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx +++ b/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx @@ -568,13 +568,28 @@ describe('useSidebarBreadcrumbs', () => { it('returns first level link', () => { const pathname = '/somePathName'; - const sidebar = [testCategory(), testLink({href: pathname})]; + const sidebar = [testCategory(), testLink({href: pathname, docId: 'doc1'})]; expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([ sidebar[1], ]); }); + it('returns doc links only', () => { + const pathname = '/somePathName'; + + // A link that is not a doc link should not appear in the breadcrumbs + // See https://github.com/facebook/docusaurus/pull/11616 + const nonDocLink = testLink({href: pathname}); + const docLink = testLink({href: pathname, docId: 'doc1'}); + + const sidebar = [testCategory(), nonDocLink, docLink]; + + expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([ + docLink, + ]); + }); + it('returns nested category', () => { const pathname = '/somePathName'; @@ -613,7 +628,7 @@ describe('useSidebarBreadcrumbs', () => { it('returns nested link', () => { const pathname = '/somePathName'; - const link = testLink({href: pathname}); + const link = testLink({href: pathname, docId: 'docNested'}); const categoryLevel3 = testCategory({ items: [testLink(), link, testLink()], @@ -657,6 +672,35 @@ describe('useSidebarBreadcrumbs', () => { createUseSidebarBreadcrumbsMock(undefined, false)('/foo'), ).toBeNull(); }); + + // Regression test for https://github.com/facebook/docusaurus/issues/11612 + it('returns the category that owns the URL, not a category with a link pointing to it', () => { + const categoryA: PropSidebarItemCategory = testCategory({ + label: 'Category A', + href: '/category-a', + items: [ + testLink({href: '/category-a/doc1', label: 'Doc 1'}), + testLink({href: '/category-a/doc2', label: 'Doc 2'}), + // This link points to Category B's generated-index + testLink({href: '/category-b', label: 'Go to Category B'}), + ], + }); + + const categoryB: PropSidebarItemCategory = testCategory({ + label: 'Category B', + href: '/category-b', + items: [ + testLink({href: '/category-b/item1', label: 'Item 1'}), + testLink({href: '/category-b/item2', label: 'Item 2'}), + ], + }); + + const sidebar: PropSidebar = [categoryA, categoryB]; + + expect(createUseSidebarBreadcrumbsMock(sidebar)('/category-b')).toEqual([ + categoryB, + ]); + }); }); describe('useCurrentSidebarCategory', () => { @@ -708,12 +752,16 @@ describe('useCurrentSidebarCategory', () => { expect(mockUseCurrentSidebarCategory('/cat2')).toEqual(category2); }); - it('works for category link item', () => { - const link = testLink({href: '/my/link/path'}); + it('works for category doc link item', () => { + const pathname = '/my/link/path'; + const nonDocLink = testLink({href: pathname}); + const docLink = testLink({href: pathname, docId: 'doc1'}); + const category: PropSidebarItemCategory = testCategory({ href: '/cat1', - items: [testLink(), testLink(), link, testCategory()], + items: [testLink(), testLink(), nonDocLink, docLink, testCategory()], }); + const sidebar: PropSidebar = [ testLink(), testLink(), @@ -724,18 +772,28 @@ describe('useCurrentSidebarCategory', () => { const mockUseCurrentSidebarCategory = createUseCurrentSidebarCategoryMock(sidebar); - expect(mockUseCurrentSidebarCategory('/my/link/path')).toEqual(category); + expect(mockUseCurrentSidebarCategory(pathname)).toEqual(category); }); it('works for nested category link item', () => { - const link = testLink({href: '/my/link/path'}); + const pathname = '/my/link/path'; + const nonDocLink = testLink({href: pathname}); + const docLink = testLink({href: pathname, docId: 'doc1'}); + const category2: PropSidebarItemCategory = testCategory({ href: '/cat2', - items: [testLink(), testLink(), link, testCategory()], + items: [ + testLink(), + testLink(), + testCategory({items: [nonDocLink]}), + nonDocLink, + docLink, + testCategory(), + ], }); const category1: PropSidebarItemCategory = testCategory({ href: '/cat1', - items: [testLink(), testLink(), category2, testCategory()], + items: [testLink(), nonDocLink, testLink(), category2, testCategory()], }); const sidebar: PropSidebar = [ testLink(), @@ -780,6 +838,38 @@ describe('useCurrentSidebarCategory', () => { `"Unexpected: cant find current sidebar in context"`, ); }); + + // Regression test for https://github.com/facebook/docusaurus/issues/11612 + it('returns the category that owns the URL, not a category with a link pointing to it', () => { + const categoryA: PropSidebarItemCategory = testCategory({ + label: 'Category A', + href: '/category-a', + items: [ + testLink({href: '/category-a/doc1', label: 'Doc 1'}), + testLink({href: '/category-a/doc2', label: 'Doc 2'}), + // This link points to Category B's generated-index + testLink({href: '/category-b', label: 'Go to Category B'}), + ], + }); + + const categoryB: PropSidebarItemCategory = testCategory({ + label: 'Category B', + href: '/category-b', + items: [ + testLink({href: '/category-b/item1', label: 'Item 1'}), + testLink({href: '/category-b/item2', label: 'Item 2'}), + ], + }); + + const sidebar: PropSidebar = [categoryA, categoryB]; + + const mockUseCurrentSidebarCategory = + createUseCurrentSidebarCategoryMock(sidebar); + + // When visiting /category-b, we should get Category B (the owner), + // not Category A (which just has a link to it) + expect(mockUseCurrentSidebarCategory('/category-b')).toEqual(categoryB); + }); }); describe('useCurrentSidebarSiblings', () => { @@ -805,10 +895,10 @@ describe('useCurrentSidebarSiblings', () => { testCategory(), ]; - const mockUseCurrentSidebarCategory = + const mockUseCurrentSidebarSiblings = createUseCurrentSidebarSiblingsMock(sidebar); - expect(mockUseCurrentSidebarCategory('/cat')).toEqual(category.items); + expect(mockUseCurrentSidebarSiblings('/cat')).toEqual(category.items); }); it('works for sidebar root', () => { @@ -823,10 +913,10 @@ describe('useCurrentSidebarSiblings', () => { testCategory(), ]; - const mockUseCurrentSidebarCategory = + const mockUseCurrentSidebarSiblings = createUseCurrentSidebarSiblingsMock(sidebar); - expect(mockUseCurrentSidebarCategory('/rootLink')).toEqual(sidebar); + expect(mockUseCurrentSidebarSiblings('/rootLink')).toEqual(sidebar); }); it('works for nested sidebar category', () => { @@ -852,10 +942,13 @@ describe('useCurrentSidebarSiblings', () => { }); it('works for category link item', () => { - const link = testLink({href: '/my/link/path'}); + const pathname = '/my/link/path'; + const nonDocLink = testLink({href: pathname}); + const docLink = testLink({href: pathname, docId: 'doc1'}); + const category: PropSidebarItemCategory = testCategory({ href: '/cat1', - items: [testLink(), testLink(), link, testCategory()], + items: [testLink(), testLink(), nonDocLink, docLink, testCategory()], }); const sidebar: PropSidebar = [ testLink(), @@ -864,23 +957,24 @@ describe('useCurrentSidebarSiblings', () => { testCategory(), ]; - const mockUseCurrentSidebarCategory = + const mockUseCurrentSidebarSiblings = createUseCurrentSidebarSiblingsMock(sidebar); - expect(mockUseCurrentSidebarCategory('/my/link/path')).toEqual( - category.items, - ); + expect(mockUseCurrentSidebarSiblings(pathname)).toEqual(category.items); }); it('works for nested category link item', () => { - const link = testLink({href: '/my/link/path'}); + const pathname = '/my/link/path'; + const nonDocLink = testLink({href: pathname}); + const docLink = testLink({href: pathname, docId: 'doc1'}); + const category2: PropSidebarItemCategory = testCategory({ href: '/cat2', - items: [testLink(), testLink(), link, testCategory()], + items: [testLink(), testLink(), nonDocLink, testCategory()], }); const category1: PropSidebarItemCategory = testCategory({ href: '/cat1', - items: [testLink(), testLink(), category2, testCategory()], + items: [testLink(), testLink(), category2, docLink, testCategory()], }); const sidebar: PropSidebar = [ testLink(), @@ -889,18 +983,16 @@ describe('useCurrentSidebarSiblings', () => { testCategory(), ]; - const mockUseCurrentSidebarCategory = + const mockUseCurrentSidebarSiblings = createUseCurrentSidebarSiblingsMock(sidebar); - expect(mockUseCurrentSidebarCategory('/my/link/path')).toEqual( - category2.items, - ); + expect(mockUseCurrentSidebarSiblings(pathname)).toEqual(category1.items); }); it('throws when sidebar is missing', () => { - const mockUseCurrentSidebarCategory = createUseCurrentSidebarSiblingsMock(); + const mockUseCurrentSidebarSiblings = createUseCurrentSidebarSiblingsMock(); expect(() => - mockUseCurrentSidebarCategory('/cat'), + mockUseCurrentSidebarSiblings('/cat'), ).toThrowErrorMatchingInlineSnapshot( `"Unexpected: cant find current sidebar in context"`, ); diff --git a/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx b/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx index aa00df8510..474a58895a 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx +++ b/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx @@ -234,15 +234,22 @@ function getSidebarBreadcrumbs({ }): PropSidebarBreadcrumbsItem[] { const breadcrumbs: PropSidebarBreadcrumbsItem[] = []; - function extract(items: PropSidebarItem[]) { + function extract(items: PropSidebarItem[]): boolean { for (const item of items) { - if ( - (item.type === 'category' && - (isSamePath(item.href, pathname) || extract(item.items))) || - (item.type === 'link' && isSamePath(item.href, pathname)) + // Extract category item + if (item.type === 'category') { + if (isSamePath(item.href, pathname) || extract(item.items)) { + breadcrumbs.unshift(item); + return true; + } + } + // Extract doc item + else if ( + item.type === 'link' && + item.docId && + isSamePath(item.href, pathname) ) { - const filtered = onlyCategories && item.type !== 'category'; - if (!filtered) { + if (!onlyCategories) { breadcrumbs.unshift(item); } return true; diff --git a/website/community/2-resources.mdx b/website/community/2-resources.mdx index 25b8362bf8..22244d224b 100644 --- a/website/community/2-resources.mdx +++ b/website/community/2-resources.mdx @@ -73,6 +73,7 @@ See the showcase - [docusaurus-i18n](https://github.com/moonrailgun/docusaurus-i18n) - Auto-translate docusaurus documents with openai. - [docusaurus-plugin-glossary](https://github.com/mcclowes/docusaurus-plugin-glossary) - A docusaurus plugin for helping users understand key terms. - [docusaurus-plugin-cookie-consent](https://github.com/mcclowes/docusaurus-plugin-cookie-consent) - A Docusaurus plugin for allowing users to opt in/out of cookies, and accessing those settings in code. +- [expose-markdown-docusaurus-plugin](https://github.com/FlyNumber/markdown_docusaurus_plugin) - A Docusaurus plugin that exposes your /docs Markdown files as raw .md URLs. (For LLM's and such). ## Enterprise usage {#enterprise-usage}