File tree 3 files changed +44
-17
lines changed
3 files changed +44
-17
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { CoderIcon } from "components/Icons/CoderIcon";
10
10
import { Loader } from "components/Loader/Loader" ;
11
11
import { Margins } from "components/Margins/Margins" ;
12
12
import { Stack } from "components/Stack/Stack" ;
13
+ import { getStaticBuildInfo } from "utils/buildInfo" ;
13
14
14
15
const fetchDynamicallyImportedModuleError =
15
16
"Failed to fetch dynamically imported module" ;
@@ -116,21 +117,6 @@ export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => {
116
117
) ;
117
118
} ;
118
119
119
- // During the build process, we inject the build info into the HTML
120
- const getStaticBuildInfo = ( ) => {
121
- const buildInfoJson = document
122
- . querySelector ( "meta[property=build-info]" )
123
- ?. getAttribute ( "content" ) ;
124
-
125
- if ( buildInfoJson ) {
126
- try {
127
- return JSON . parse ( buildInfoJson ) as BuildInfoResponse ;
128
- } catch {
129
- return undefined ;
130
- }
131
- }
132
- } ;
133
-
134
120
const styles = {
135
121
root : {
136
122
paddingTop : 32 ,
Original file line number Diff line number Diff line change
1
+ import type { BuildInfoResponse } from "api/typesGenerated" ;
2
+
3
+ let CACHED_BUILD_INFO : BuildInfoResponse | undefined ;
4
+
5
+ // During the build process, we inject the build info into the HTML
6
+ export const getStaticBuildInfo = ( ) => {
7
+ if ( CACHED_BUILD_INFO ) {
8
+ return CACHED_BUILD_INFO ;
9
+ }
10
+
11
+ const buildInfoJson = document
12
+ . querySelector ( "meta[property=build-info]" )
13
+ ?. getAttribute ( "content" ) ;
14
+
15
+ if ( buildInfoJson ) {
16
+ try {
17
+ CACHED_BUILD_INFO = JSON . parse ( buildInfoJson ) as BuildInfoResponse ;
18
+ } catch {
19
+ return undefined ;
20
+ }
21
+ }
22
+
23
+ return CACHED_BUILD_INFO ;
24
+ } ;
Original file line number Diff line number Diff line change 1
- const DEFAULT_DOCS_URL = "https://coder.com/docs" ;
1
+ import { getStaticBuildInfo } from "./buildInfo" ;
2
+
3
+ function defaultDocsUrl ( ) : string {
4
+ const docsUrl = "https://coder.com/docs" ;
5
+ // If we can get the specific version, we want to include that in default docs URL.
6
+ let version = getStaticBuildInfo ( ) ?. version ;
7
+ if ( ! version ) {
8
+ return docsUrl ;
9
+ }
10
+
11
+ // Strip the postfix version info that's not part of the link.
12
+ const i = version ?. indexOf ( "-" ) ?? - 1 ;
13
+ if ( i >= 0 ) {
14
+ version = version . slice ( 0 , i ) ;
15
+ }
16
+ return `${ docsUrl } /@${ version } ` ;
17
+ }
2
18
3
19
// Add cache to avoid DOM reading all the time
4
20
let CACHED_DOCS_URL : string | undefined ;
@@ -12,8 +28,9 @@ const getBaseDocsURL = () => {
12
28
const docsUrl = document
13
29
. querySelector < HTMLMetaElement > ( 'meta[property="docs-url"]' )
14
30
?. getAttribute ( "content" ) ;
31
+
15
32
const isValidDocsURL = docsUrl && isURL ( docsUrl ) ;
16
- CACHED_DOCS_URL = isValidDocsURL ? docsUrl : DEFAULT_DOCS_URL ;
33
+ CACHED_DOCS_URL = isValidDocsURL ? docsUrl : defaultDocsUrl ( ) ;
17
34
}
18
35
return CACHED_DOCS_URL ;
19
36
} ;
You can’t perform that action at this time.
0 commit comments