Skip to content

Instantly share code, notes, and snippets.

@colin-haber
Created May 9, 2024 14:33
Show Gist options
  • Save colin-haber/5502852a145559a081e03f99c997f688 to your computer and use it in GitHub Desktop.
Save colin-haber/5502852a145559a081e03f99c997f688 to your computer and use it in GitHub Desktop.
var forceVersion = '5.3';
var apiVersionRegex = /docs\.unrealengine\.com\/(?<apiVersion>\d+\.\d+)\/(?<languageTag>[0-9A-Za-z\-]+)\/(?<docPath>.*)$/;
var url = document.location.href;
var match = apiVersionRegex.exec(url);
var isVersionForced = typeof forceVersion !== 'undefined' && !isNaN(parseFloat(forceVersion));
if (match !== null) {
var apiVersion = match.groups['apiVersion'];
var languageTag = match.groups['languageTag'];
var docPath = match.groups['docPath'];
if (apiVersion !== undefined && languageTag !== undefined && docPath !== undefined) {
var forceMajorVersion;
var redirectUrl;
if (isVersionForced) {
forceMajorVersion = parseInt(forceVersion.split('.')[0]);
if (forceMajorVersion < 5) {
redirectUrl = `https://docs.unrealengine.com/${forceVersion}/${languageTag}/${docPath}`;
} else {
redirectUrl = `https://dev.epicgames.com/documentation/${languageTag}/unreal-engine/${docPath}?application_version=${forceVersion}`;
}
} else {
redirectUrl = `https://dev.epicgames.com/documentation/${languageTag}/unreal-engine/${docPath}`;
}
window.location.replace(redirectUrl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment