fix: decodeURI to support non-english slugs

This commit is contained in:
Timothy Lin 2023-07-24 17:06:28 +08:00
parent 2d3b825246
commit ed54f2fcaf
2 changed files with 6 additions and 10 deletions

View File

@ -13,8 +13,8 @@ export async function generateMetadata({
}: {
params: { slug: string[] }
}): Promise<Metadata | undefined> {
const slug = params.slug.join('/')
const post = allBlogs.find((p) => encodeURIComponent(p.slug) === slug)
const slug = decodeURI(params.slug.join('/'))
const post = allBlogs.find((p) => p.slug === slug)
const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author)
@ -68,16 +68,12 @@ export const generateStaticParams = async () => {
}
export default async function Page({ params }: { params: { slug: string[] } }) {
const slug = params.slug.join('/')
const slug = decodeURI(params.slug.join('/'))
const sortedPosts = sortedBlogPost(allBlogs) as Blog[]
const postIndex = sortedPosts.findIndex(
(p) => encodeURIComponent(p.slug) === encodeURIComponent(slug)
)
const postIndex = sortedPosts.findIndex((p) => p.slug === slug)
const prev = coreContent(sortedPosts[postIndex + 1])
const next = coreContent(sortedPosts[postIndex - 1])
const post = sortedPosts.find(
(p) => encodeURIComponent(p.slug) === encodeURIComponent(slug)
) as Blog
const post = sortedPosts.find((p) => p.slug === slug) as Blog
const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author)

View File

@ -1 +1 @@
{"markdown":1,"code":1,"features":1,"next-js":5,"math":1,"ols":1,"github":1,"guide":4,"tailwind":2,"holiday":1,"canada":1,"images":1,"writings":1,"book":1,"reflection":1,"multi-author":1,"feature":1}
{"markdown":3,"code":3,"features":3,"next-js":5,"math":1,"ols":1,"github":1,"guide":4,"tailwind":2,"holiday":1,"canada":1,"images":1,"writings":1,"book":1,"reflection":1,"multi-author":1,"feature":1}