feat: made stuff
This commit is contained in:
@@ -27,6 +27,32 @@ export default function makeSlug(basePath: string): Route {
|
||||
}
|
||||
}
|
||||
|
||||
// For multi-segment slugs (e.g. "overview/12345"), try
|
||||
// partials/<dir>/[param].tsx and inject the param into context.params
|
||||
if (!page && slug.includes("/")) {
|
||||
const idx = slug.indexOf("/");
|
||||
const dir = slug.slice(0, idx);
|
||||
const param = slug.slice(idx + 1);
|
||||
|
||||
// Discover the dynamic segment name from the file system
|
||||
try {
|
||||
const entries: string[] = [];
|
||||
for await (const entry of Deno.readDir(`${basePath}/partials/${dir}`)) {
|
||||
if (entry.isFile) entries.push(entry.name);
|
||||
}
|
||||
const dynFile = entries.find((n) =>
|
||||
n.startsWith("[") && n.endsWith("].tsx")
|
||||
);
|
||||
if (dynFile) {
|
||||
const paramName = dynFile.slice(1, -5); // "[numEtud].tsx" → "numEtud"
|
||||
context.params[paramName] = param;
|
||||
page = (await import(`${basePath}/partials/${dir}/${dynFile}`)).Page;
|
||||
}
|
||||
} catch {
|
||||
// directory doesn't exist or no dynamic file
|
||||
}
|
||||
}
|
||||
|
||||
if (!page) {
|
||||
return context.renderNotFound();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user