Files
brk/website_next/routes.js
T
2026-06-16 23:37:03 +02:00

39 lines
1.0 KiB
JavaScript

import { createBuildPage } from "./build/index.js";
import { createExplorePage } from "./explore/index.js";
import { createHomePage } from "./home/index.js";
import { createLearnPage } from "./learn/index.js";
import { createWalletsPage } from "./wallets/index.js";
/** @type {Record<string, () => HTMLElement>} */
const routes = {
"/": createHomePage,
"/explore": createExplorePage,
"/learn": createLearnPage,
"/build": createBuildPage,
"/wallets": createWalletsPage,
};
/** @param {string} pathname */
function canonicalPath(pathname) {
return pathname !== "/" && pathname.endsWith("/")
? pathname.slice(0, -1)
: pathname;
}
/** @param {string} pathname */
export function resolvePath(pathname) {
const path = canonicalPath(pathname);
return path in routes ? path : undefined;
}
/** @param {string} pathname */
export function normalizePath(pathname) {
return resolvePath(pathname) ?? "/";
}
/** @param {string} pathname */
export function createRoutePage(pathname) {
return routes[pathname]();
}