From 4a06bb0379f1c8b4c3f16c8cc23622c9144597a8 Mon Sep 17 00:00:00 2001 From: Shinya Fujino Date: Wed, 30 Aug 2023 10:10:42 +0900 Subject: [PATCH] i18n(ja): Update content-collections.mdx for v3 (#4396) Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> --- src/content/docs/ja/guides/content-collections.mdx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/content/docs/ja/guides/content-collections.mdx b/src/content/docs/ja/guides/content-collections.mdx index b209e3f6adadf..5e934cf5f6ee8 100644 --- a/src/content/docs/ja/guides/content-collections.mdx +++ b/src/content/docs/ja/guides/content-collections.mdx @@ -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/'); @@ -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学習者 | ブログ',