Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created December 19, 2022 11:05
Show Gist options
  • Save deleteman/825bb0f61d66b0cafb9fff81d1ceb156 to your computer and use it in GitHub Desktop.
Save deleteman/825bb0f61d66b0cafb9fff81d1ceb156 to your computer and use it in GitHub Desktop.
<script >
import { getVersionFromURL } from "~/util";
//code to update the links inside the documents to make sure they link to the right
//version
let links = document.getElementsByTagName("a")
let version = getVersionFromURL(window.location.href)
const host = import.meta.env.PUBLIC_SITE_URL ? import.meta.env.PUBLIC_SITE_URL : ""
let urlParts = ["docs"]
if(version != "") { //if we're not on the default version (the latest)
version = "v" + version
urlParts.push(version)
}
for(let l of links){
if(l.href.indexOf(host) != -1) {
let uri = l.href.replace(host, "")
uri = uri.replace(`/docs`, "").replace(/\/v[0-9]+\.[0-9]+\.[0-9]+\//, "")
urlParts.push(uri)
l.setAttribute("href", urlParts.join("/").replace("//", "/"))
urlParts.pop()
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment