Skip to content

Commit

Permalink
Fix the banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Dec 6, 2024
1 parent a9f76b4 commit 9abeaf4
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/theme/DocVersionBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,40 @@ type BannerLabelComponentProps = {
versionMetadata: PropVersionMetadata;
};

const unreleasedMessage =
"This documentation is for an unreleased version of Teleport.";
const selfHostedMessage =
"This documentation is for a version of Teleport that is only available for self-hosted clusters.";

function UnreleasedVersionLabel({
siteTitle,
versionMetadata,
}: BannerLabelComponentProps) {
const { versions } = useDocusaurusContext().siteConfig.plugins.find((p) => {
return p[0] == "@docusaurus/plugin-content-docs";
})[1];
const { versions, lastVersion } =
useDocusaurusContext().siteConfig.plugins.find((p) => {
return p[0] == "@docusaurus/plugin-content-docs";
})[1];
const verToOrder = new Map();
const vers = Object.keys(versions);
for (let i = 0; i < vers.length; i++) {
verToOrder.set(i, versions[vers[i]]);
verToOrder.set(vers[i], i);
}

const { version } = useDocsVersion();
let message: string;
const thisIdx = verToOrder.get(version);
// Set a version banner. Indicate if the version is the edge version or
// only available for self-hosted users. The latter situation happens when
// the latest release is not yet the latest version in the docs.
if (
verToOrder.get(lastVersion) < thisIdx &&
verToOrder.get("current") > thisIdx
) {
message = selfHostedMessage;
} else {
message = unreleasedMessage;
}

return (
<Translate
id="theme.docs.versions.unreleasedVersionLabel"
Expand All @@ -42,7 +64,7 @@ function UnreleasedVersionLabel({
versionLabel: <b>{versionMetadata.label}</b>,
}}
>
{"This documentation is for an unreleased version of Teleport."}
{message}
</Translate>
);
}
Expand All @@ -54,13 +76,13 @@ function UnmaintainedVersionLabel({
return (
<Translate
id="theme.docs.versions.unmaintainedVersionLabel"
description="Indicates that the user is browsing an unmaintained docs version"
description="Indicates that the user is browsing a previous (but still maintained) docs version"
values={{
siteTitle,
versionLabel: <b>{versionMetadata.label}</b>,
}}
>
{"This is documentation for {siteTitle} {versionLabel}."}
{"This is documentation for {siteTitle} {versionLabel}, a previous version of Teleport."}
</Translate>
);
}
Expand Down

0 comments on commit 9abeaf4

Please sign in to comment.