Revert to simpler link parsing and run formatter

This commit is contained in:
Priere 2023-12-06 03:57:30 -05:00
parent 5332f99a5a
commit 8e9b607fa1
2 changed files with 15 additions and 20 deletions

View File

@ -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);
}; };
} }

View File

@ -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">![Strudel Icon](/icons/strudel_icon.png)</div>
![Strudel Icon](/icons/strudel_icon.png)
</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.