Skip to content

Commit

Permalink
i18n(ja): Update content-collections.mdx for v3 (#4396)
Browse files Browse the repository at this point in the history
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
  • Loading branch information
morinokami and yanthomasdev authored Aug 30, 2023
1 parent 3cd09f3 commit 4a06bb0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/content/docs/ja/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,20 @@ const publishedBlogEntries = await getCollection('blog', ({ data }) => {
});
```

開発サーバーの実行時にのみ閲覧可能で、本番用にはビルドされない下書き(draft)ページも作成できます。

```js
// 例: 本番用にビルドするときにのみ、`draft: true`を含むエントリーを除外
import { getCollection } from 'astro:content';
const blogEntries = await getCollection('blog', ({ data }) => {
return import.meta.env.PROD ? data.draft !== true : true;
});
```

filterの引数は、コレクション内の入れ子ディレクトリによるフィルタリングもサポートします。`id`にはネストされた完全なパスが含まれるので、各`id`の先頭でフィルタリングして、特定のネストされたディレクトリからのアイテムだけを返せます。

```js
//コレクション内のサブディレクトリによるエントリーのフィルタリング
//: コレクション内のサブディレクトリによるエントリーのフィルタリング
import { getCollection } from 'astro:content';
const englishDocsEntries = await getCollection('docs', ({ id }) => {
return id.startsWith('en/');
Expand Down Expand Up @@ -705,7 +715,7 @@ const { Content } = await entry.render();
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
export async function get() {
export async function GET() {
const posts = await getCollection('posts');
return rss({
title: 'Astro学習者 | ブログ',
Expand Down

0 comments on commit 4a06bb0

Please sign in to comment.