-
-
Notifications
You must be signed in to change notification settings - Fork 838
i18n(ja): added translation for route-data
#3462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,139 @@ | ||||||
| --- | ||||||
| title: ルートデータ | ||||||
| description: Starlight のページデータモデルがどのようにページをレンダリングするか、またそのカスタマイズ方法について学びましょう。 | ||||||
| --- | ||||||
|
|
||||||
| import { Steps } from '@astrojs/starlight/components'; | ||||||
|
|
||||||
| Starlight がドキュメント内のページをレンダリングするとき、まずそのページ上の内容を表すルートデータオブジェクトを作成します。 | ||||||
| このガイドでは、ルートデータがどのように生成され、どのように使用されるか、また Starlight の既定の動作を変更するためにカスタマイズする方法を説明します。 | ||||||
|
|
||||||
| 利用可能なすべてのプロパティ一覧については、[「ルートデータリファレンス」](/ja/reference/route-data/) を参照してください。 | ||||||
|
|
||||||
| ## ルートデータとは? | ||||||
|
|
||||||
| Starlight のルートデータは、1 ページをレンダリングするために必要なすべての情報を含むオブジェクトです。 | ||||||
| これは、現在のページに関する情報に加え、Starlight の設定から生成されるデータも含みます。 | ||||||
|
|
||||||
| ## ルートデータの使用方法 | ||||||
|
|
||||||
| Starlight のすべてのコンポーネントは、ルートデータを使用して各ページで何をレンダリングするかを決定します。 | ||||||
| たとえば、[`siteTitle`](/ja/reference/route-data/#sitetitle) 文字列はサイトタイトルの表示に使用され、[`sidebar`](/ja/reference/route-data/#sidebar) 配列はグローバルサイドバーのナビゲーションをレンダリングするために使用されます。 | ||||||
|
|
||||||
| このデータは Astro コンポーネント内で `Astro.locals.starlightRoute` グローバルからアクセスできます。 | ||||||
|
|
||||||
| ```astro title="example.astro" {2} | ||||||
| --- | ||||||
| const { siteTitle } = Astro.locals.starlightRoute; | ||||||
| --- | ||||||
|
|
||||||
| <p>このサイトのタイトルは「{siteTitle}」です。</p> | ||||||
| ``` | ||||||
|
|
||||||
| これは、表示内容をカスタマイズするために [コンポーネントのオーバーライド](/ja/guides/overriding-components/) を作成するときなどに便利です。 | ||||||
|
|
||||||
| ## ルートデータのカスタマイズ | ||||||
|
|
||||||
| Starlight のルートデータは、設定なしでそのまま動作します。 | ||||||
| しかし、高度なユースケースでは、サイトの表示方法を変更するために一部またはすべてのページでルートデータをカスタマイズしたい場合があります。 | ||||||
|
|
||||||
| これは [コンポーネントのオーバーライド](/ja/guides/overriding-components/) と似た概念ですが、Starlight がデータを「どのように」レンダリングするかを変更する代わりに、Starlight が「レンダリングするデータ自体」を変更します。 | ||||||
|
|
||||||
| ### ルートデータをカスタマイズすべき場合 | ||||||
|
|
||||||
| 既存の設定オプションでは実現できない形で、Starlight がデータを処理する方法を変更したい場合にルートデータのカスタマイズが役立ちます。 | ||||||
|
|
||||||
| たとえば、サイドバー項目をフィルタリングしたり、特定のページのタイトルをカスタマイズしたりできます。 | ||||||
| このような変更は、Starlight の既定コンポーネントを変更することなく、これらのコンポーネントに渡すデータを修正するだけで実現できます。 | ||||||
|
|
||||||
| ### ルートデータをカスタマイズする方法 | ||||||
|
|
||||||
| ルートデータは特別な形式の「ミドルウェア」を使ってカスタマイズできます。 | ||||||
| これは Starlight がページをレンダリングするたびに呼び出され、ルートデータオブジェクト内の値を変更できる関数です。 | ||||||
|
|
||||||
| <Steps> | ||||||
|
|
||||||
| 1. Starlight の `defineRouteMiddleware()` ユーティリティを使って、`onRequest` 関数をエクスポートする新しいファイルを作成します。 | ||||||
|
|
||||||
| ```ts | ||||||
| // src/routeData.ts | ||||||
| import { defineRouteMiddleware } from '@astrojs/starlight/route-data'; | ||||||
|
|
||||||
| export const onRequest = defineRouteMiddleware(() => {}); | ||||||
| ``` | ||||||
|
|
||||||
| 2. `astro.config.mjs` で、ルートデータミドルウェアファイルの場所を Starlight に指定します。 | ||||||
|
|
||||||
| ```js ins={9} | ||||||
| // astro.config.mjs | ||||||
| import { defineConfig } from 'astro/config'; | ||||||
| import starlight from '@astrojs/starlight'; | ||||||
|
|
||||||
| export default defineConfig({ | ||||||
| integrations: [ | ||||||
| starlight({ | ||||||
| title: 'My delightful docs site', | ||||||
| routeMiddleware: './src/routeData.ts', | ||||||
| }), | ||||||
| ], | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| 3. `onRequest` 関数を更新してルートデータを変更します。 | ||||||
|
|
||||||
| ミドルウェアが最初に受け取る引数は [Astro の `context` オブジェクト](https://docs.astro.build/en/reference/api-reference/) です。 | ||||||
|
||||||
| ミドルウェアが最初に受け取る引数は [Astro の `context` オブジェクト](https://docs.astro.build/en/reference/api-reference/) です。 | |
| ミドルウェアが最初に受け取る引数は [Astro の `context` オブジェクト](https://docs.astro.build/ja/reference/api-reference/) です。 |
We can link to the Japanese version of the Astro Docs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: b05eacc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here regarding the title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: ba1f7e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably translate this title for consistency with most of other examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: ba1f7e5