From 3220602f205394ec183c68dd548612fbf9878ee2 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 23 Jan 2024 23:50:13 +0900 Subject: [PATCH] update --- src/app/[...slug]/page.tsx | 4 ++-- src/utils/slug.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index eb3b8e9..8e3f6c7 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -30,7 +30,7 @@ const cachedFindByPath = cache(async (path: string) => { // https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#opting-out-of-data-caching export async function generateMetadata({ params: { slug }}: { params: { slug: Array }}): Promise { - const sluggized = await sluggize(slug, ''); + const sluggized = await sluggize(slug); const content = await cachedFindByPath(sluggized); return generateForArticleOrPage(sluggized ,content.body); } @@ -45,7 +45,7 @@ async function run(req: any): Promise { } async function get(req: any) { - let path = req.params.slug.join("/"); + let path = sluggize(req.params.slug); // TODO move utils & write testcode if (!path.startsWith("/")) { path = "/" + path; diff --git a/src/utils/slug.ts b/src/utils/slug.ts index 56a8d41..5c6f19f 100644 --- a/src/utils/slug.ts +++ b/src/utils/slug.ts @@ -1,5 +1,7 @@ + +// FIXME: messy code (I'm tired to fight wiht TS type) export function sluggize( - slug: any, // NOTE: Next.js request context is any. + slug: Array | string, // NOTE: Next.js request context seems . prefix: string | undefined = undefined, fallback: string | undefined = undefined ) { @@ -9,8 +11,8 @@ export function sluggize( const s = slug as Array; const arr = [p].concat(s); return arr.join('/'); - } else { - return fallback; + } else { + return slug; } } catch { return fallback;