Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
16 changes: 1 addition & 15 deletionssite/src/components/ErrorBoundary/RuntimeErrorState.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ import { CoderIcon } from "components/Icons/CoderIcon";
import { Loader } from "components/Loader/Loader";
import { Margins } from "components/Margins/Margins";
import { Stack } from "components/Stack/Stack";
import { getStaticBuildInfo } from "utils/buildInfo";

const fetchDynamicallyImportedModuleError =
"Failed to fetch dynamically imported module";
Expand DownExpand Up@@ -116,21 +117,6 @@ export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => {
);
};

// During the build process, we inject the build info into the HTML
const getStaticBuildInfo = () => {
const buildInfoJson = document
.querySelector("meta[property=build-info]")
?.getAttribute("content");

if (buildInfoJson) {
try {
return JSON.parse(buildInfoJson) as BuildInfoResponse;
} catch {
return undefined;
}
}
};

const styles = {
root: {
paddingTop: 32,
Expand Down
24 changes: 24 additions & 0 deletionssite/src/utils/buildInfo.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
import type { BuildInfoResponse } from "api/typesGenerated";

let CACHED_BUILD_INFO: BuildInfoResponse | undefined;

// During the build process, we inject the build info into the HTML
export const getStaticBuildInfo = () => {
if (CACHED_BUILD_INFO) {
return CACHED_BUILD_INFO;
}

const buildInfoJson = document
.querySelector("meta[property=build-info]")
?.getAttribute("content");

if (buildInfoJson) {
try {
CACHED_BUILD_INFO = JSON.parse(buildInfoJson) as BuildInfoResponse;
} catch {
return undefined;
}
}

return CACHED_BUILD_INFO;
};
21 changes: 19 additions & 2 deletionssite/src/utils/docs.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
const DEFAULT_DOCS_URL = "https://coder.com/docs";
import { getStaticBuildInfo } from "./buildInfo";

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.
let version = getStaticBuildInfo()?.version;
if (!version) {
return docsUrl;
}

// Strip the postfix version info that's not part of the link.
const i = version?.indexOf("-") ?? -1;
if (i >= 0) {
version = version.slice(0, i);
}
return `${docsUrl}/@${version}`;
}

// Add cache to avoid DOM reading all the time
let CACHED_DOCS_URL: string | undefined;
Expand All@@ -12,8 +28,9 @@ const getBaseDocsURL = () => {
const docsUrl = document
.querySelector<HTMLMetaElement>('meta[property="docs-url"]')
?.getAttribute("content");

const isValidDocsURL = docsUrl && isURL(docsUrl);
CACHED_DOCS_URL = isValidDocsURL ? docsUrl :DEFAULT_DOCS_URL;
CACHED_DOCS_URL = isValidDocsURL ? docsUrl :defaultDocsUrl();
}
return CACHED_DOCS_URL;
};
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp