Astro 项目,比如我的 blog 分类下再分日期存放文章,编译时就会报错: Expected "slug" to match "[^\/#\?]+?", but got "2023-12-13/text"
。
文件位置:/src/content/blog/2023-12-13/text.md
如果全部放在 /src/content/blog/
目录下就不会有问题。
有熟悉 Astro 的大佬知道怎么解吗?
![]() | 1 blankmiss 2023-12-14 10:32:02 +08:00 Astro 是什么 下面地址也不贴一个吗 |
![]() | 2 blankmiss 2023-12-14 10:32:18 +08:00 下面地址 --> 项目地址 |
![]() | 3 LavaC 2023-12-14 10:36:51 +08:00 这么放是没问题的,应该是你其它地方写错了,看看[...slug].astro |
4 Deshun OP @LavaC [...slug].astro 是在 /blog 下面: ``` --- export const prerender = true import { getEntryBySlug, getCollection } from "astro:content"; import PostLayout from '$/layouts/post.astro'; export async function getStaticPaths() { const allPosts = await getCollection('blog'); return allPosts.map(post => ({ params: { slug: post.slug } })) } const { slug } = Astro.params const entry = await getEntryBySlug('blog', slug!) const { Content } = await entry.render() --- <PostLayout slug={slug} cOntent={entry.data} > <Content/> </PostLayout> ``` |
![]() | 5 LavaC 2023-12-14 10:58:14 +08:00 @Deshun 怪了,参照 issue[#7121]( https://github.com/withastro/astro/issues/7121),同样的代码我也只会在文件叫[slug]而非[...slug]时编译报错。 |