Skip to content

Commit 8328884

Browse files
Fix: Version numbering automatically updates again (#884)
We only conditionally replace this _if_ there is a version number in the code block, because this breaks syntax highlighting. This is kind of a cheap hack, and we should really be replacing the strings with version numbers further upstream before they get broken into syntax highlighting chunks, that way we get to keep both working version numbers, as well as syntax highlighting. I tried messing around with contentlayer to replace these strings further upstream, but I couldn't figure it out within my timeboxed session. Hence leaving this PR as it is, because it's fairly important that correct version numbers be displayed and copied by our customers. ## Pull Request approval You will need to get your PR approved by at least one member of the Sourcegraph team. For reviews of docs formatting, styles, and component usage, please tag the docs team via the #docs Slack channel.
1 parent 35b7f12 commit 8328884

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/components/PreCodeBlock.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,15 @@ export async function PreCodeBlock({ children, ...props }: PreProps) {
7272

7373
const version = await getLatestVersion()
7474
const version_no_v = trimPrefix(version, "v")
75+
let mustReplaceVersions = false
76+
if (codeContent.includes("{CURRENT_VERSION}") || codeContent.includes("{CURRENT_VERSION_NO_V}")) {
77+
mustReplaceVersions = true
78+
}
7579
codeContent = codeContent.replace(/{CURRENT_VERSION}/g, version)
7680
codeContent = codeContent.replace(/{CURRENT_VERSION_NO_V}/g, version_no_v)
81+
if (mustReplaceVersions) {
82+
children = codeContent
83+
}
7784

7885
return (
7986
<div className="relative">

0 commit comments

Comments
 (0)