mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-01 16:00:29 +02:00
fix(v2): allow relative sidebar path resolution in docs:version command (#4861)
* fix(v2): allow relative sidebar path resolution in docs:version command * factorize sidebarPath option resolution logic + dogfood Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
65cf8dacee
commit
35bdde3409
4 changed files with 26 additions and 6 deletions
|
@ -25,11 +25,13 @@ import {
|
|||
SidebarItemsGeneratorVersion,
|
||||
NumberPrefixParser,
|
||||
SidebarItemsGeneratorOption,
|
||||
PluginOptions,
|
||||
} from './types';
|
||||
import {mapValues, flatten, flatMap, difference, pick, memoize} from 'lodash';
|
||||
import {getElementsAround} from '@docusaurus/utils';
|
||||
import combinePromises from 'combine-promises';
|
||||
import {DefaultSidebarItemsGenerator} from './sidebarItemsGenerator';
|
||||
import path from 'path';
|
||||
|
||||
type SidebarItemCategoryJSON = SidebarItemBase & {
|
||||
type: 'category';
|
||||
|
@ -256,7 +258,19 @@ export const DefaultSidebars: UnprocessedSidebars = {
|
|||
|
||||
export const DisabledSidebars: UnprocessedSidebars = {};
|
||||
|
||||
// If a path is provided, make it absolute
|
||||
// use this before loadSidebars()
|
||||
export function resolveSidebarPathOption(
|
||||
siteDir: string,
|
||||
sidebarPathOption: PluginOptions['sidebarPath'],
|
||||
): PluginOptions['sidebarPath'] {
|
||||
return sidebarPathOption
|
||||
? path.resolve(siteDir, sidebarPathOption)
|
||||
: sidebarPathOption;
|
||||
}
|
||||
|
||||
// TODO refactor: make async
|
||||
// Note: sidebarFilePath must be absolute, use resolveSidebarPathOption
|
||||
export function loadSidebars(
|
||||
sidebarFilePath: string | false | undefined,
|
||||
): UnprocessedSidebars {
|
||||
|
@ -279,6 +293,7 @@ export function loadSidebars(
|
|||
|
||||
// We don't want sidebars to be cached because of hot reloading.
|
||||
const sidebarJson = importFresh(sidebarFilePath) as SidebarsJSON;
|
||||
|
||||
return normalizeSidebars(sidebarJson);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue