fix: encode both slug and path

This commit is contained in:
Timothy Lin 2023-07-24 00:21:24 +08:00
parent cd8dc0a230
commit 2d3b825246

View File

@ -69,12 +69,15 @@ export const generateStaticParams = async () => {
export default async function Page({ params }: { params: { slug: string[] } }) {
const slug = params.slug.join('/')
console.log('begin generate for slug: %o', slug)
const sortedPosts = sortedBlogPost(allBlogs) as Blog[]
const postIndex = sortedPosts.findIndex((p) => encodeURIComponent(p.slug) === slug)
const postIndex = sortedPosts.findIndex(
(p) => encodeURIComponent(p.slug) === encodeURIComponent(slug)
)
const prev = coreContent(sortedPosts[postIndex + 1])
const next = coreContent(sortedPosts[postIndex - 1])
const post = sortedPosts.find((p) => encodeURIComponent(p.slug) === slug) as Blog
const post = sortedPosts.find(
(p) => encodeURIComponent(p.slug) === encodeURIComponent(slug)
) as Blog
const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author)