From 85fe09b13e78e71e21fdc4972d02e54d1a843f7d Mon Sep 17 00:00:00 2001 From: Timothy Lin Date: Thu, 31 Oct 2024 22:37:40 +0800 Subject: [PATCH] apply async codemod --- app/blog/[...slug]/page.tsx | 10 +++++----- app/blog/page/[page]/page.tsx | 3 ++- app/tags/[tag]/page.tsx | 8 ++++++-- scripts/rss.mjs | 4 +--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/blog/[...slug]/page.tsx b/app/blog/[...slug]/page.tsx index 1598622..f0c1831 100644 --- a/app/blog/[...slug]/page.tsx +++ b/app/blog/[...slug]/page.tsx @@ -21,11 +21,10 @@ const layouts = { PostBanner, } -export async function generateMetadata({ - params, -}: { - params: { slug: string[] } +export async function generateMetadata(props: { + params: Promise<{ slug: string[] }> }): Promise { + const params = await props.params const slug = decodeURI(params.slug.join('/')) const post = allBlogs.find((p) => p.slug === slug) const authorList = post?.authors || ['default'] @@ -78,7 +77,8 @@ export const generateStaticParams = async () => { return allBlogs.map((p) => ({ slug: p.slug.split('/').map((name) => decodeURI(name)) })) } -export default async function Page({ params }: { params: { slug: string[] } }) { +export default async function Page(props: { params: Promise<{ slug: string[] }> }) { + const params = await props.params const slug = decodeURI(params.slug.join('/')) // Filter out drafts in production const sortedCoreContents = allCoreContent(sortPosts(allBlogs)) diff --git a/app/blog/page/[page]/page.tsx b/app/blog/page/[page]/page.tsx index a0a8b48..bdd2703 100644 --- a/app/blog/page/[page]/page.tsx +++ b/app/blog/page/[page]/page.tsx @@ -11,7 +11,8 @@ export const generateStaticParams = async () => { return paths } -export default function Page({ params }: { params: { page: string } }) { +export default async function Page(props: { params: Promise<{ page: string }> }) { + const params = await props.params const posts = allCoreContent(sortPosts(allBlogs)) const pageNumber = parseInt(params.page as string) const initialDisplayPosts = posts.slice( diff --git a/app/tags/[tag]/page.tsx b/app/tags/[tag]/page.tsx index 94a3dd2..ba3591f 100644 --- a/app/tags/[tag]/page.tsx +++ b/app/tags/[tag]/page.tsx @@ -8,7 +8,10 @@ import { genPageMetadata } from 'app/seo' import { Metadata } from 'next' import { notFound } from 'next/navigation' -export async function generateMetadata({ params }: { params: { tag: string } }): Promise { +export async function generateMetadata(props: { + params: Promise<{ tag: string }> +}): Promise { + const params = await props.params const tag = decodeURI(params.tag) return genPageMetadata({ title: tag, @@ -31,7 +34,8 @@ export const generateStaticParams = async () => { return paths } -export default function TagPage({ params }: { params: { tag: string } }) { +export default async function TagPage(props: { params: Promise<{ tag: string }> }) { + const params = await props.params const tag = decodeURI(params.tag) // Capitalize first letter and convert space to dash const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1) diff --git a/scripts/rss.mjs b/scripts/rss.mjs index f493257..e454152 100644 --- a/scripts/rss.mjs +++ b/scripts/rss.mjs @@ -47,9 +47,7 @@ async function generateRSS(config, allBlogs, page = 'feed.xml') { if (publishPosts.length > 0) { for (const tag of Object.keys(tagData)) { - const filteredPosts = allBlogs.filter((post) => - post.tags.map((t) => slug(t)).includes(tag) - ) + const filteredPosts = allBlogs.filter((post) => post.tags.map((t) => slug(t)).includes(tag)) const rss = generateRss(config, filteredPosts, `tags/${tag}/${page}`) const rssPath = path.join(outputFolder, 'tags', tag) mkdirSync(rssPath, { recursive: true })