Skip to content

fix: add version information to default docs links #14205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
only add version info to default url
  • Loading branch information
bcpeinhardt committed Aug 7, 2024
commit d573e102f4aed8e4946b4ff457b86c134d227a4a
15 changes: 7 additions & 8 deletions site/src/utils/docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { getStaticBuildInfo } from "./buildInfo";

const DEFAULT_DOCS_URL = "https://coder.com/docs";
function defaultDocsUrl(): string {
const docsUrl = "https://coder.com/docs";
// If we can get the specific version, we want to include that in default docs URL.
const version = getStaticBuildInfo()?.version.split("-")[0];
return version ? `${docsUrl}/@${version}` : docsUrl;
}

// Add cache to avoid DOM reading all the time
let CACHED_DOCS_URL: string | undefined;
Expand All @@ -16,13 +21,7 @@ const getBaseDocsURL = () => {
?.getAttribute("content");

const isValidDocsURL = docsUrl && isURL(docsUrl);
CACHED_DOCS_URL = isValidDocsURL ? docsUrl : DEFAULT_DOCS_URL;

// If we can get the specific version, we want to include that in docs links
const version = getStaticBuildInfo()?.version.split("-")[0];
if (version) {
CACHED_DOCS_URL = `${CACHED_DOCS_URL}/@${version}`;
}
CACHED_DOCS_URL = isValidDocsURL ? docsUrl : defaultDocsUrl();
}
return CACHED_DOCS_URL;
};
Expand Down
Loading