feat: new docs options: versions.{badge,className} (#5454)

* docs: add versions.{badge,className} options

* remove badge option test
This commit is contained in:
Sébastien Lorber 2021-08-31 15:40:37 +02:00 committed by GitHub
parent 914e204dcb
commit 42e70e6d42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 93 additions and 17 deletions

View file

@ -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,