Astro 多层目录报错,有大佬知道怎么解决吗

203 天前
 Deshun

Astro 项目,比如我的 blog 分类下再分日期存放文章,编译时就会报错: Expected "slug" to match "[^\/#\?]+?", but got "2023-12-13/text"

文件位置:/src/content/blog/2023-12-13/text.md

如果全部放在 /src/content/blog/ 目录下就不会有问题。

有熟悉 Astro 的大佬知道怎么解吗?

981 次点击
所在节点    程序员
6 条回复
blankmiss
203 天前
Astro 是什么 下面地址也不贴一个吗
blankmiss
203 天前
下面地址 --> 项目地址
LavaC
203 天前
这么放是没问题的,应该是你其它地方写错了,看看[...slug].astro
Deshun
203 天前
@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>
```
LavaC
203 天前
@Deshun 怪了,参照 issue[#7121]( https://github.com/withastro/astro/issues/7121),同样的代码我也只会在文件叫[slug]而非[...slug]时编译报错。
Deshun
203 天前
@LavaC 非常感谢,问题解决。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1000249

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX