Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
liruifengv authored Sep 14, 2024
2 parents 323cf24 + 686efba commit b6f81b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/content/docs/ko/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ import Avatar from '~/components/Avatar.astro';
```astro
---
import { getUser } from '../api';
const user = await getUser(Astro.locals.userId);
---
<img class="avatar" src={user.imageUrl}>
Expand Down
36 changes: 18 additions & 18 deletions src/content/docs/zh-cn/tutorial/5-astro-api/2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,24 @@ import { Steps } from '@astrojs/starlight/components';

3. 替换 `getStaticPaths` 函数的 `return`

```js title="src/pages/tags/[tag].astro" del={1-8} ins={10-16}
return [
{params: {tag: "astro"}, props: {posts: allPosts}},
{params: {tag: "successes"}, props: {posts: allPosts}},
{params: {tag: "community"}, props: {posts: allPosts}},
{params: {tag: "blogging"}, props: {posts: allPosts}},
{params: {tag: "setbacks"}, props: {posts: allPosts}},
{params: {tag: "learning in public"}, props: {posts: allPosts}}
]

return uniqueTags.map((tag) => {
const filteredPosts = allPosts.filter((post) => post.frontmatter.tags.includes(tag));
return {
params: { tag },
props: { posts: filteredPosts },
};
});
```
```js title="src/pages/tags/[tag].astro" del={1-8} ins={10-16}
return [
{params: {tag: "astro"}, props: {posts: allPosts}},
{params: {tag: "successes"}, props: {posts: allPosts}},
{params: {tag: "community"}, props: {posts: allPosts}},
{params: {tag: "blogging"}, props: {posts: allPosts}},
{params: {tag: "setbacks"}, props: {posts: allPosts}},
{params: {tag: "learning in public"}, props: {posts: allPosts}}
]

return uniqueTags.map((tag) => {
const filteredPosts = allPosts.filter((post) => post.frontmatter.tags.includes(tag));
return {
params: { tag },
props: { posts: filteredPosts },
};
});
```

`getStaticPaths` 函数应始终返回一个包含 `params`(用于每个页面路由的名称)的对象列表,并且可以选择包含任何 `props`(要传递给这些页面的数据)。之前,你为你所知道的每个博客中使用的标签名称定义了一个参数,并将整个文章列表作为 props 传递给每个页面。

Expand Down

0 comments on commit b6f81b6

Please sign in to comment.