9a4c6863d1
- Add stages module with full CRUD API and admin overview island - Add mobility overview island (Liste, Kanban, Detail CRUD views) - Add contract PDF upload/download endpoints for mobilites - Add light/dark theme toggle in header - Add employeeOnly flag to hide entire modules from students (admin, students, stages) - Add read-only GET endpoints for modules/ues/ue-modules in notes module - Add [slug].tsx catch-all routes for direct URL navigation - Replace old mobility table with mobilites + stages schema (migration 0004) - Allow students to create mobilites and upload contracts - Redirect authenticated users from / to /apps catalog
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { FreshContext } from "$fresh/server.ts";
|
|
import { Route, State } from "$root/defaults/interfaces.ts";
|
|
import { ComponentChildren } from "preact";
|
|
|
|
/**
|
|
* Generates a catch-all [slug] route that dynamically loads partials.
|
|
* This enables direct URL navigation to sub-pages (e.g. /admin/modules).
|
|
* @param basePath The base path of the module, should be `import.meta.dirname!`.
|
|
* @returns A route handler that loads the partial matching the slug.
|
|
*/
|
|
export default function makeSlug(basePath: string): Route {
|
|
return async function SlugRoute(
|
|
request: Request,
|
|
context: FreshContext<State>,
|
|
): Promise<ComponentChildren | Response> {
|
|
const slug = context.params.slug;
|
|
|
|
// Try partials/<slug>.tsx, then partials/(admin)/<slug>.tsx
|
|
let page: Route | undefined;
|
|
try {
|
|
page = (await import(`${basePath}/partials/${slug}.tsx`)).Page;
|
|
} catch {
|
|
try {
|
|
page = (await import(`${basePath}/partials/(admin)/${slug}.tsx`)).Page;
|
|
} catch {
|
|
// No partial found for this slug
|
|
}
|
|
}
|
|
|
|
if (!page) {
|
|
return context.renderNotFound();
|
|
}
|
|
|
|
return page(request, context);
|
|
};
|
|
}
|