1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

docs: use URL instead of strings to check urls

This commit is contained in:
Thomas Heartman 2023-01-05 22:54:39 +01:00
parent daf1ec05c1
commit be9cad8a61
No known key found for this signature in database
GPG Key ID: 47CFBB2D87C87664

View File

@ -71,19 +71,21 @@ const replaceLinks = ({ content, repo }) => {
const markdownLink = /(?<=\[.*\]\(\s?)(\S+)(?=.*\))/g;
const replacer = (url) => {
// case 2:
const docsUrl = 'https://docs.getunleash.io';
if (url.startsWith(docsUrl)) {
return url.substring(docsUrl.length);
}
// case 1
try {
// This constructor will throw if the URL is relative.
// https://developer.mozilla.org/en-US/docs/Web/API/URL/URL
new URL(url);
const parsedUrl = new URL(url);
// case 2:
if (parsedUrl.hostname === 'docs.getunleash.io') {
return `${parsedUrl.pathname ?? '/'}${parsedUrl.query ?? ''}${
parsedUrl.hash ?? ''
}`;
}
return url;
} catch {
// case 1
if (url.startsWith('#')) {
// ignore links to other doc sections
return url;