Created
December 19, 2022 11:05
-
-
Save deleteman/825bb0f61d66b0cafb9fff81d1ceb156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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