mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
Revert to simpler link parsing and run formatter
This commit is contained in:
parent
5332f99a5a
commit
8e9b607fa1
@ -17,7 +17,7 @@ const baseNoTrailing = base.endsWith('/') ? base.slice(0, -1) : base;
|
|||||||
|
|
||||||
// this rehype plugin fixes relative links
|
// this rehype plugin fixes relative links
|
||||||
// it works by prepending the base + page path to anchor links
|
// it works by prepending the base + page path to anchor links
|
||||||
// and by prepending the base path to all other relative links
|
// and by prepending the base path to other relative links starting with /
|
||||||
// this is necessary when using a base href like <base href={base} />
|
// this is necessary when using a base href like <base href={base} />
|
||||||
// examples with base as "mybase":
|
// examples with base as "mybase":
|
||||||
// #gain -> /mybase/learn/effects/#gain
|
// #gain -> /mybase/learn/effects/#gain
|
||||||
@ -27,23 +27,20 @@ function relativeURLFix() {
|
|||||||
const chunks = file.history[0].split('/src/pages/'); // file.history[0] is the file path
|
const chunks = file.history[0].split('/src/pages/'); // file.history[0] is the file path
|
||||||
const path = chunks[chunks.length - 1].slice(0, -4); // only path inside src/pages, without .mdx
|
const path = chunks[chunks.length - 1].slice(0, -4); // only path inside src/pages, without .mdx
|
||||||
return rehypeUrls((url) => {
|
return rehypeUrls((url) => {
|
||||||
// NOTE: the base argument to the URL constructor is ignored if the input is already
|
let newHref = baseNoTrailing;
|
||||||
// absolute and used if not, which facilitates the comparison below
|
if (url.href.startsWith('#')) {
|
||||||
// true if origins are same, and relative urls are considered as origin equal to site var value
|
// special case: a relative anchor link to the current page
|
||||||
if (new URL(site).origin === new URL(url.href, site).origin) {
|
newHref += `/${path}/${url.href}`;
|
||||||
let newHref = baseNoTrailing;
|
} else if (url.href.startsWith('/')) {
|
||||||
if (url.href.startsWith('#')) {
|
// any other relative url starting with /
|
||||||
// special case: a relative anchor link to the current page
|
// NOTE: this does strip off serialized queries and fragments
|
||||||
newHref += `/${path}/${url.href}`;
|
newHref += url.pathname.endsWith('/') ? url.pathname : url.pathname + '/';
|
||||||
} else {
|
} else {
|
||||||
// any other same origin link
|
// leave this URL alone
|
||||||
// NOTE: this does strip off serialized queries and fragments
|
return;
|
||||||
newHref += (url.pathname.endsWith('/') ? url.pathname : url.pathname + '/');
|
|
||||||
}
|
|
||||||
// console.log(url.href + ' -> ', newHref);
|
|
||||||
return newHref;
|
|
||||||
}
|
}
|
||||||
return;
|
// console.log(url.href + ' -> ', newHref);
|
||||||
|
return newHref;
|
||||||
})(tree);
|
})(tree);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,7 @@ import { MiniRepl } from '../../docs/MiniRepl';
|
|||||||
|
|
||||||
# Welcome
|
# Welcome
|
||||||
|
|
||||||
<div className="w-32 animate-pulse md:float-right ml-8">
|
<div className="w-32 animate-pulse md:float-right ml-8"></div>
|
||||||

|
|
||||||
</div>
|
|
||||||
|
|
||||||
Welcome to the Strudel documentation pages!
|
Welcome to the Strudel documentation pages!
|
||||||
You've come to the right place if you want to learn how to make music with code.
|
You've come to the right place if you want to learn how to make music with code.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user