Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 23, 2024
1 parent ffe98f6 commit 3220602
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> }}): Promise<Metadata> {
const sluggized = await sluggize(slug, '');
const sluggized = await sluggize(slug);
const content = await cachedFindByPath(sluggized);
return generateForArticleOrPage(sluggized ,content.body);
}
Expand All @@ -45,7 +45,7 @@ async function run(req: any): Promise<any> {
}

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;
Expand Down
8 changes: 5 additions & 3 deletions src/utils/slug.ts
Original file line number Diff line number Diff line change
@@ -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> | string, // NOTE: Next.js request context seems <any>.
prefix: string | undefined = undefined,
fallback: string | undefined = undefined
) {
Expand All @@ -9,8 +11,8 @@ export function sluggize(
const s = slug as Array<string>;
const arr = [p].concat(s);
return arr.join('/');
} else {
return fallback;
} else {
return slug;
}
} catch {
return fallback;
Expand Down

0 comments on commit 3220602

Please sign in to comment.