in packages/docusaurus-plugin-content-docs/src/versions.ts [185:366]
sidebarFilePath: resolveSidebarPathOption(
context.siteDir,
options.sidebarPath,
),
};
}
return {
contentPath: path.join(
getVersionedDocsDirPath(context.siteDir, options.id),
`version-${versionName}`,
),
contentPathLocalized,
sidebarFilePath: path.join(
getVersionedSidebarsDirPath(context.siteDir, options.id),
`version-${versionName}-sidebars.json`,
),
};
}
function getVersionEditUrls({
contentPath,
contentPathLocalized,
context: {siteDir, i18n},
options: {
id,
path: currentVersionPath,
editUrl: editUrlOption,
editCurrentVersion,
},
}: {
contentPath: string;
contentPathLocalized: string;
context: Pick<LoadContext, 'siteDir' | 'i18n'>;
options: Pick<
PluginOptions,
'id' | 'path' | 'editUrl' | 'editCurrentVersion'
>;
}): Pick<VersionMetadata, 'editUrl' | 'editUrlLocalized'> {
// If the user is using the functional form of editUrl,
// she has total freedom and we can't compute a "version edit url"
if (!editUrlOption || typeof editUrlOption === 'function') {
return {editUrl: undefined, editUrlLocalized: undefined};
}
const editDirPath = editCurrentVersion ? currentVersionPath : contentPath;
const editDirPathLocalized = editCurrentVersion
? getDocsDirPathLocalized({
siteDir,
locale: i18n.currentLocale,
versionName: CURRENT_VERSION_NAME,
pluginId: id,
})
: contentPathLocalized;
const versionPathSegment = posixPath(
path.relative(siteDir, path.resolve(siteDir, editDirPath)),
);
const versionPathSegmentLocalized = posixPath(
path.relative(siteDir, path.resolve(siteDir, editDirPathLocalized)),
);
const editUrl = normalizeUrl([editUrlOption, versionPathSegment]);
const editUrlLocalized = normalizeUrl([
editUrlOption,
versionPathSegmentLocalized,
]);
return {
editUrl,
editUrlLocalized,
};
}
export function getDefaultVersionBanner({
versionName,
versionNames,
lastVersionName,
}: {
versionName: string;
versionNames: string[];
lastVersionName: string;
}): VersionBanner | null {
// Current version: good, no banner
if (versionName === lastVersionName) {
return null;
}
// Upcoming versions: unreleased banner
if (
versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)
) {
return 'unreleased';
}
// Older versions: display unmaintained banner
return 'unmaintained';
}
export function getVersionBanner({
versionName,
versionNames,
lastVersionName,
options,
}: {
versionName: string;
versionNames: string[];
lastVersionName: string;
options: Pick<PluginOptions, 'versions'>;
}): VersionBanner | null {
const versionBannerOption = options.versions[versionName]?.banner;
if (versionBannerOption) {
return versionBannerOption === 'none' ? null : versionBannerOption;
}
return getDefaultVersionBanner({
versionName,
versionNames,
lastVersionName,
});
}
export 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,
lastVersionName,
context,
options,
}: {
versionName: string;
versionNames: string[];
lastVersionName: string;
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
options: Pick<
PluginOptions,
| 'id'
| 'path'
| 'sidebarPath'
| 'routeBasePath'
| 'tagsBasePath'
| 'versions'
| 'editUrl'
| 'editCurrentVersion'
>;
}): VersionMetadata {
const {sidebarFilePath, contentPath, contentPathLocalized} =
getVersionMetadataPaths({versionName, context, options});
const isLast = versionName === lastVersionName;
// retro-compatible values
const defaultVersionLabel =
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
function getDefaultVersionPathPart() {
if (isLast) {