mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
feat: new docs options: versions.{badge,className} (#5454)
* docs: add versions.{badge,className} options * remove badge option test
This commit is contained in:
parent
914e204dcb
commit
42e70e6d42
12 changed files with 93 additions and 17 deletions
|
@ -304,6 +304,35 @@ function getVersionBanner({
|
|||
);
|
||||
}
|
||||
|
||||
function getVersionBadge({
|
||||
versionName,
|
||||
versionNames,
|
||||
options,
|
||||
}: {
|
||||
versionName: string;
|
||||
versionNames: string[];
|
||||
options: Pick<PluginOptions, 'versions'>;
|
||||
}): boolean {
|
||||
const versionBadgeOption = options.versions[versionName]?.badge;
|
||||
// If site is not versioned or only one version is included
|
||||
// we don't show the version badge by default
|
||||
// See https://github.com/facebook/docusaurus/issues/3362
|
||||
const versionBadgeDefault = versionNames.length !== 1;
|
||||
return versionBadgeOption ?? versionBadgeDefault;
|
||||
}
|
||||
|
||||
function getVersionClassName({
|
||||
versionName,
|
||||
options,
|
||||
}: {
|
||||
versionName: string;
|
||||
options: Pick<PluginOptions, 'versions'>;
|
||||
}): string {
|
||||
const versionClassNameOption = options.versions[versionName]?.className;
|
||||
const versionClassNameDefault = `docs-version-${versionName}`;
|
||||
return versionClassNameOption ?? versionClassNameDefault;
|
||||
}
|
||||
|
||||
function createVersionMetadata({
|
||||
versionName,
|
||||
versionNames,
|
||||
|
@ -387,6 +416,8 @@ function createVersionMetadata({
|
|||
lastVersionName,
|
||||
options,
|
||||
}),
|
||||
versionBadge: getVersionBadge({versionName, versionNames, options}),
|
||||
versionClassName: getVersionClassName({versionName, options}),
|
||||
isLast,
|
||||
routePriority,
|
||||
sidebarFilePath,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue