diff --git a/packages/web/src/layouts/Layout.astro b/packages/web/src/layouts/Layout.astro index 8cdbd09..a25cb00 100644 --- a/packages/web/src/layouts/Layout.astro +++ b/packages/web/src/layouts/Layout.astro @@ -2,15 +2,24 @@ import Header from "../components/Header.astro"; import Footer from "../components/Footer.astro"; import TopArrow from "../components/TopArrow.astro"; +import type { Routes } from "../routes/router"; +import { routerLabels } from "../routes/router"; +import { asArray } from "../lib/utils"; + +type Path = Routes<["footer-only", "disabled"]>; interface Props { - title?: string; + path: Path | Path[]; } -let title = "Trampoline Intercité"; -if (Astro.props.title) { - title += " | " + Astro.props.title; -} +const paths = asArray(Astro.props.path); +const labels = paths.reduce( + (acc, path) => ({ ...acc, [path]: routerLabels[path] }), + {} as Record, +); + +const label = labels[paths[0]]; +const title = "Trampoline Intercité" + (label ? ` | ${label}` : ""); --- @@ -94,3 +103,12 @@ if (Astro.props.title) { } }); + + diff --git a/packages/web/src/lib/utils.ts b/packages/web/src/lib/utils.ts new file mode 100644 index 0000000..5aa5954 --- /dev/null +++ b/packages/web/src/lib/utils.ts @@ -0,0 +1,3 @@ +export function asArray(x: T | T[]) { + return Array.isArray(x) ? x : [x] +} diff --git a/packages/web/src/pages/404.astro b/packages/web/src/pages/404.astro index 2a24b60..5f64070 100644 --- a/packages/web/src/pages/404.astro +++ b/packages/web/src/pages/404.astro @@ -3,7 +3,7 @@ import Logo from "../components/Logo.astro"; import Layout from "../layouts/Layout.astro"; --- - +
diff --git a/packages/web/src/pages/horaire.astro b/packages/web/src/pages/horaire.astro index 3f3526b..a53a05c 100644 --- a/packages/web/src/pages/horaire.astro +++ b/packages/web/src/pages/horaire.astro @@ -2,4 +2,4 @@ import Layout from "../layouts/Layout.astro"; --- -horaire +horaire diff --git a/packages/web/src/pages/index.astro b/packages/web/src/pages/index.astro index 4aba332..9749970 100644 --- a/packages/web/src/pages/index.astro +++ b/packages/web/src/pages/index.astro @@ -2,4 +2,4 @@ import Layout from "../layouts/Layout.astro"; --- -INDEX +INDEX diff --git a/packages/web/src/routes/router.ts b/packages/web/src/routes/router.ts index 8c64678..9a8108c 100644 --- a/packages/web/src/routes/router.ts +++ b/packages/web/src/routes/router.ts @@ -1,5 +1,5 @@ import type { FilterRoutes, ListRoutes, RouteArray, RouteModifer } from "./routes" -import { filter } from "./routes" +import { filter, labels } from "./routes" export const router = [ { path: "/", label: "Accueil", modifiers: ["footer-only"] }, @@ -26,10 +26,13 @@ export const router = [ ] }, { path: "/horaire", label: "Horaire", icon: "date_range" }, - { path: "/contact", label: "Contact", icon: "call" } + { path: "/contact", label: "Contact", icon: "call" }, + { path: "/404", label: "404", modifiers: ['disabled'] } ] as const router satisfies RouteArray export const headerRouter = filter(['header-only'], router) export const footerRouter = filter(['footer-only'], router) export type Routes = ListRoutes> + +export const routerLabels = labels(router) diff --git a/packages/web/src/routes/routes.ts b/packages/web/src/routes/routes.ts index cb0d007..4f20797 100644 --- a/packages/web/src/routes/routes.ts +++ b/packages/web/src/routes/routes.ts @@ -32,6 +32,16 @@ export const filter = ( .filter(route => (route.modifiers ?? []).every(modifier => allowed.includes(modifier))) .map(route => "subroutes" in route ? ({ ...route, subroutes: filter(allowed, route.subroutes!) }) : route) as FilterRoutes +export type Labels = { [key in ListRoutes]: string } + +export const labels = (routes: R): Labels => { + return routes.reduce((acc, route) => ({ + ...acc, + [route.path]: route.label, + ...('subroutes' in route ? labels(route.subroutes!) : {}) + }), {} as Labels) +} + export type ListRoutes = R extends readonly [infer First extends Route, ...infer Rest extends RouteArray] ? First['path'] | @@ -39,6 +49,3 @@ export type ListRoutes = First['subroutes'] extends RouteArray ? ListRoutes : never ) : never - - -