File tree Expand file tree Collapse file tree 3 files changed +44
-17
lines changed
Expand file tree Collapse file tree 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";
1010import { Loader } from "components/Loader/Loader" ;
1111import { Margins } from "components/Margins/Margins" ;
1212import { Stack } from "components/Stack/Stack" ;
13+ import { getStaticBuildInfo } from "utils/buildInfo" ;
1314
1415const fetchDynamicallyImportedModuleError =
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- 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-
134120const styles = {
135121 root : {
136122 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+ }
218
319// Add cache to avoid DOM reading all the time
420let CACHED_DOCS_URL : string | undefined ;
@@ -12,8 +28,9 @@ const getBaseDocsURL = () => {
1228 const docsUrl = document
1329 . querySelector < HTMLMetaElement > ( 'meta[property="docs-url"]' )
1430 ?. getAttribute ( "content" ) ;
31+
1532 const isValidDocsURL = docsUrl && isURL ( docsUrl ) ;
16- CACHED_DOCS_URL = isValidDocsURL ? docsUrl : DEFAULT_DOCS_URL ;
33+ CACHED_DOCS_URL = isValidDocsURL ? docsUrl : defaultDocsUrl ( ) ;
1734 }
1835 return CACHED_DOCS_URL ;
1936} ;
You can’t perform that action at this time.
0 commit comments