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

Commitd6c4d47

Browse files
fix: add version information to default docs links (#14205)
add version information to default docs links---------Co-authored-by: Kayla Washburn-Love <mckayla@hey.com>
1 parent2e05329 commitd6c4d47

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

‎site/src/components/ErrorBoundary/RuntimeErrorState.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CoderIcon } from "components/Icons/CoderIcon";
1010
import{Loader}from"components/Loader/Loader";
1111
import{Margins}from"components/Margins/Margins";
1212
import{Stack}from"components/Stack/Stack";
13+
import{getStaticBuildInfo}from"utils/buildInfo";
1314

1415
constfetchDynamicallyImportedModuleError=
1516
"Failed to fetch dynamically imported module";
@@ -116,21 +117,6 @@ export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => {
116117
);
117118
};
118119

119-
// During the build process, we inject the build info into the HTML
120-
constgetStaticBuildInfo=()=>{
121-
constbuildInfoJson=document
122-
.querySelector("meta[property=build-info]")
123-
?.getAttribute("content");
124-
125-
if(buildInfoJson){
126-
try{
127-
returnJSON.parse(buildInfoJson)asBuildInfoResponse;
128-
}catch{
129-
returnundefined;
130-
}
131-
}
132-
};
133-
134120
conststyles={
135121
root:{
136122
paddingTop:32,

‎site/src/utils/buildInfo.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
importtype{BuildInfoResponse}from"api/typesGenerated";
2+
3+
letCACHED_BUILD_INFO:BuildInfoResponse|undefined;
4+
5+
// During the build process, we inject the build info into the HTML
6+
exportconstgetStaticBuildInfo=()=>{
7+
if(CACHED_BUILD_INFO){
8+
returnCACHED_BUILD_INFO;
9+
}
10+
11+
constbuildInfoJson=document
12+
.querySelector("meta[property=build-info]")
13+
?.getAttribute("content");
14+
15+
if(buildInfoJson){
16+
try{
17+
CACHED_BUILD_INFO=JSON.parse(buildInfoJson)asBuildInfoResponse;
18+
}catch{
19+
returnundefined;
20+
}
21+
}
22+
23+
returnCACHED_BUILD_INFO;
24+
};

‎site/src/utils/docs.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
constDEFAULT_DOCS_URL="https://coder.com/docs";
1+
import{getStaticBuildInfo}from"./buildInfo";
2+
3+
functiondefaultDocsUrl():string{
4+
constdocsUrl="https://coder.com/docs";
5+
// If we can get the specific version, we want to include that in default docs URL.
6+
letversion=getStaticBuildInfo()?.version;
7+
if(!version){
8+
returndocsUrl;
9+
}
10+
11+
// Strip the postfix version info that's not part of the link.
12+
consti=version?.indexOf("-")??-1;
13+
if(i>=0){
14+
version=version.slice(0,i);
15+
}
16+
return`${docsUrl}/@${version}`;
17+
}
218

319
// Add cache to avoid DOM reading all the time
420
letCACHED_DOCS_URL:string|undefined;
@@ -12,8 +28,9 @@ const getBaseDocsURL = () => {
1228
constdocsUrl=document
1329
.querySelector<HTMLMetaElement>('meta[property="docs-url"]')
1430
?.getAttribute("content");
31+
1532
constisValidDocsURL=docsUrl&&isURL(docsUrl);
16-
CACHED_DOCS_URL=isValidDocsURL ?docsUrl :DEFAULT_DOCS_URL;
33+
CACHED_DOCS_URL=isValidDocsURL ?docsUrl :defaultDocsUrl();
1734
}
1835
returnCACHED_DOCS_URL;
1936
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp