Repository navigation
Fix/versioned js sidebars #12792
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
Fix/versioned js sidebars #12792
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import {describe, expect, it} from 'vitest'; | ||
| import path from 'path'; | ||
| import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; | ||
| import {getVersionSidebarsPath, resolveVersionSidebarsPath} from '../files'; | ||
|
|
||
| describe('getVersionSidebarsPath', () => { | ||
| it('returns the JSON versioned sidebar path', async () => { | ||
| expect(getVersionSidebarsPath('/site', DEFAULT_PLUGIN_ID, '1.0.0')).toBe( | ||
| path.join('/site', 'versioned_sidebars', 'version-1.0.0-sidebars.json'), | ||
| ); | ||
| }); | ||
| it('returns the JSON versioned sidebar path when using a version name', async () => { | ||
| expect(getVersionSidebarsPath('/site', DEFAULT_PLUGIN_ID, '2.0.0')).toBe( | ||
| path.join('/site', 'versioned_sidebars', 'version-2.0.0-sidebars.json'), | ||
| ); | ||
| }); | ||
| it('returns the JavaScript versioned sidebar path when it exists', async () => { | ||
| const siteDir = path.join(__dirname, 'fixtures'); | ||
| const expectedPath = path.join( | ||
| siteDir, | ||
| 'versioned_sidebars', | ||
| 'version-1.0.0-sidebars.js', | ||
| ); | ||
|
|
||
| await expect( | ||
| resolveVersionSidebarsPath(siteDir, DEFAULT_PLUGIN_ID, '1.0.0'), | ||
| ).resolves.toBe(expectedPath); | ||
| }); | ||
| it('falls back to the JSON versioned sidebar path when no JavaScript file exists', async () => { | ||
| const siteDir = '/site'; | ||
| const expectedPath = path.join( | ||
| siteDir, | ||
| 'versioned_sidebars', | ||
| 'version-1.0.0-sidebars.json', | ||
| ); | ||
|
|
||
| await expect( | ||
| resolveVersionSidebarsPath(siteDir, DEFAULT_PLUGIN_ID, '1.0.0'), | ||
| ).resolves.toBe(expectedPath); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| docs: { | ||
| Test: ['foo/bar', 'foo/baz'], | ||
| Guides: ['hello'], | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-resolve the sidebar when its extension changes.
If a developer converts a versioned sidebar from JSON to JavaScript while the dev server is running, the cached metadata still points to JSON.
getPathsToWatch()also watches only that selected path, so the new JavaScript file is not picked up until a restart. Watch both candidate paths and resolve the sidebar again on content reload. (raw.githubusercontent.com)