报错提示无法获取posts的类型,我照抄的astro官方文档:
- ---
- import BaseLayout from "../../layouts/BaseLayout.astro";
- export async function getStaticPaths() {
- const allPosts = await Astro.glob('../posts/*.md');
- const uniqueTags = [...new Set(allPosts.map((post) => post.frontmatter.tags).flat())];
- return uniqueTags.map((tag) => {
- const filteredPosts = allPosts.filter((post) => post.frontmatter.tags.includes(tag));
- return {
- params: { tag },
- props: { posts: filteredPosts },
- };
- });
- }
- const { tag } = Astro.params;
- const { posts } = Astro.props;
- ---
- <BaseLayout>
- <p>包含「{tag}」标签的文章</p>
- <ul>
- {posts.map((post) => <li><a href={post.url}>{post.frontmatter.title}</a></li>)}
- </ul>
- </BaseLayout>
复制代码
|