dynamic sidebar elements based on routes on disk

This commit is contained in:
2025-08-17 22:11:26 +02:00
parent 21581bd9e5
commit c94a2bf5d9
3 changed files with 31 additions and 31 deletions

View File

@@ -0,0 +1,23 @@
import { prerender } from '$app/server';
export const allRoutes = prerender(() => {
const modules = import.meta.glob('/src/routes/**/+page.svelte');
const routes = Object.keys(modules).map((path) => {
console.log(path);
// Remove '/src/routes' prefix and '+page.svelte' suffix
let route = path.replace('/src/routes', '').replace('/+page.svelte', '');
// Handle the root route
route = route.toString().split('/')[1];
return route;
});
const allRoute = [...new Set(routes)].map((r: string) => {
return {
name: r?.length > 1 ? r[0].toUpperCase() + r.slice(1, r.length) : r,
path: '/' + r
};
});
return [{name: 'Home', path: '/'}, ...allRoute].filter(r => r.name);
});