apply async codemod

This commit is contained in:
Timothy Lin 2024-10-31 22:37:40 +08:00
parent c7c61a8609
commit 85fe09b13e
4 changed files with 14 additions and 11 deletions

View File

@ -21,11 +21,10 @@ const layouts = {
PostBanner, PostBanner,
} }
export async function generateMetadata({ export async function generateMetadata(props: {
params, params: Promise<{ slug: string[] }>
}: {
params: { slug: string[] }
}): Promise<Metadata | undefined> { }): Promise<Metadata | undefined> {
const params = await props.params
const slug = decodeURI(params.slug.join('/')) const slug = decodeURI(params.slug.join('/'))
const post = allBlogs.find((p) => p.slug === slug) const post = allBlogs.find((p) => p.slug === slug)
const authorList = post?.authors || ['default'] 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)) })) 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('/')) const slug = decodeURI(params.slug.join('/'))
// Filter out drafts in production // Filter out drafts in production
const sortedCoreContents = allCoreContent(sortPosts(allBlogs)) const sortedCoreContents = allCoreContent(sortPosts(allBlogs))

View File

@ -11,7 +11,8 @@ export const generateStaticParams = async () => {
return paths 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 posts = allCoreContent(sortPosts(allBlogs))
const pageNumber = parseInt(params.page as string) const pageNumber = parseInt(params.page as string)
const initialDisplayPosts = posts.slice( const initialDisplayPosts = posts.slice(

View File

@ -8,7 +8,10 @@ import { genPageMetadata } from 'app/seo'
import { Metadata } from 'next' import { Metadata } from 'next'
import { notFound } from 'next/navigation' import { notFound } from 'next/navigation'
export async function generateMetadata({ params }: { params: { tag: string } }): Promise<Metadata> { export async function generateMetadata(props: {
params: Promise<{ tag: string }>
}): Promise<Metadata> {
const params = await props.params
const tag = decodeURI(params.tag) const tag = decodeURI(params.tag)
return genPageMetadata({ return genPageMetadata({
title: tag, title: tag,
@ -31,7 +34,8 @@ export const generateStaticParams = async () => {
return paths 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) const tag = decodeURI(params.tag)
// Capitalize first letter and convert space to dash // Capitalize first letter and convert space to dash
const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1) const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1)

View File

@ -47,9 +47,7 @@ async function generateRSS(config, allBlogs, page = 'feed.xml') {
if (publishPosts.length > 0) { if (publishPosts.length > 0) {
for (const tag of Object.keys(tagData)) { for (const tag of Object.keys(tagData)) {
const filteredPosts = allBlogs.filter((post) => const filteredPosts = allBlogs.filter((post) => post.tags.map((t) => slug(t)).includes(tag))
post.tags.map((t) => slug(t)).includes(tag)
)
const rss = generateRss(config, filteredPosts, `tags/${tag}/${page}`) const rss = generateRss(config, filteredPosts, `tags/${tag}/${page}`)
const rssPath = path.join(outputFolder, 'tags', tag) const rssPath = path.join(outputFolder, 'tags', tag)
mkdirSync(rssPath, { recursive: true }) mkdirSync(rssPath, { recursive: true })