You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/sites/svelte.dev/src/routes/+layout.server.js

30 lines
572 B

export const load = async ({ url, fetch }) => {
const nav_list = await fetch('/nav.json').then((r) => r.json());
return {
nav_title: get_nav_title(url),
nav_links: nav_list
};
};
/** @param {URL} url */
function get_nav_title(url) {
const list = new Map([
[/^docs/, 'Docs'],
[/^repl/, 'REPL'],
[/^blog/, 'Blog'],
[/^faq/, 'FAQ'],
[/^tutorial/, 'Tutorial'],
[/^search/, 'Search'],
[/^examples/, 'Examples']
]);
for (const [regex, title] of list) {
if (regex.test(url.pathname.replace(/^\/(.+)/, '$1'))) {
return title;
}
}
return '';
}