in packages/docusaurus-plugin-content-docs/src/versions.ts [334:418]
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) {
return '';
}
return versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
}
const defaultVersionPathPart = getDefaultVersionPathPart();
const versionOptions = options.versions[versionName] ?? {};
const label = versionOptions.label ?? defaultVersionLabel;
const versionPathPart = versionOptions.path ?? defaultVersionPathPart;
const routePath = normalizeUrl([
context.baseUrl,
options.routeBasePath,
versionPathPart,
]);
const versionEditUrls = getVersionEditUrls({
contentPath,
contentPathLocalized,
context,
options,
});
const routePriority = versionPathPart === '' ? -1 : undefined;
// the path that will be used to refer the docs tags
// example below will be using /docs/tags
const tagsPath = normalizeUrl([routePath, options.tagsBasePath]);
return {
versionName,
label,
path: routePath,
tagsPath,
editUrl: versionEditUrls.editUrl,
editUrlLocalized: versionEditUrls.editUrlLocalized,
banner: getVersionBanner({
versionName,
versionNames,
lastVersionName,
options,
}),
badge: getVersionBadge({versionName, versionNames, options}),
className: getVersionClassName({versionName, options}),
isLast,
routePriority,
sidebarFilePath,
contentPath,
contentPathLocalized,
};
}