Astro Docs
このジェネレーターは、Astro と Starlight ドキュメントテーマを使用したドキュメントサイトをスキャフォールドします。デフォルトで、ローカライゼーション、再利用可能なコンテンツスニペット、ロケール対応の内部リンク、および starlight-blog プラグインを設定します。
また、デフォルトで Amazon Bedrock 上の Strands Agent を使用した自動翻訳パイプラインもスキャフォールドします。
Astro ドキュメントサイトの生成
Section titled “Astro ドキュメントサイトの生成”新しい Astro ドキュメントサイトは 2 つの方法で生成できます:
pnpm nx g @aws/nx-plugin:ts#docsyarn nx g @aws/nx-plugin:ts#docsnpx nx g @aws/nx-plugin:ts#docsbunx nx g @aws/nx-plugin:ts#docs- インストール Nx Console VSCode Plugin まだインストールしていない場合
- VSCodeでNxコンソールを開く
- クリック
Generate (UI)"Common Nx Commands"セクションで - 検索
@aws/nx-plugin - ts#docs - 必須パラメータを入力
- クリック
Generate
| パラメータ | 型 | デフォルト | 説明 |
|---|---|---|---|
| name 必須 | string | docs | ドキュメントプロジェクトの名前。 |
| directory | string | . | ドキュメントプロジェクトが配置される親ディレクトリ。 |
| subDirectory | string | - | ドキュメントプロジェクトが配置されるサブディレクトリ。デフォルトはケバブケースのプロジェクト名。 |
| framework | astro | astro | 使用するドキュメントフレームワーク。 |
| noTranslation | boolean | 自動ドキュメント翻訳パイプライン(Strands Agent on Amazon Bedrock + `translate` プロジェクトターゲット)をオプトアウトする。 | |
| noBlog | boolean | `starlight-blog` プラグインとサンプルブログ投稿をオプトアウトする。 | |
| preferInstallDependencies | boolean | true | ジェネレーター実行後に依存関係のインストールを優先するかどうか。複数のジェネレーターをバッチ処理する際にインストールを延期する場合はfalseに設定します(後続のジェネレーターがNxプロジェクトグラフを計算できるよう、必要に応じてインストールは実行されます)。最後に一度だけインストールします。 |
ジェネレーターの出力
Section titled “ジェネレーターの出力”デフォルトでは、ジェネレーターはワークスペースルートの docs/ に以下のプロジェクト構造を作成します(name、directory、subDirectory オプションで設定可能):
- astro.config.mjs Astro + Starlight configuration (locales, sidebar, blog plugin)
- tsconfig.json Extends astro/tsconfigs/strict with @components / @assets path aliases
- project.json Nx project with
build,start,preview(andtranslateif enabled) targets Directoryscripts
- translate.ts Translation driver — a Strands agent with a scoped file-editor tool (omitted with
--noTranslation) - translate.config.json Source/target locales, glob patterns, model id, region (omitted with
--noTranslation)
- translate.ts Translation driver — a Strands agent with a scoped file-editor tool (omitted with
Directorysrc
Directorycomponents
- link.astro Locale-aware link component (resolves paths against the current locale)
- snippet.astro Locale-aware snippet loader component
Directorycontent
Directorydocs
Directoryen
- index.mdx Landing page
Directoryguides
- getting-started.mdx Sample guide referencing the link and snippet components
Directoryblog
- welcome.mdx Sample blog post (omitted with
--noBlog)
- welcome.mdx Sample blog post (omitted with
Directorysnippets
- example.mdx Sample reusable snippet
Directorystyles
- custom.css Starlight theme overrides
- README.md Project README
ローカライゼーション
Section titled “ローカライゼーション”ジェネレーターはデフォルトで単一のロケール(en)を使用し、ルート URL をそこにリダイレクトします。さらに言語を追加するには:
astro.config.mjsのlocalesにエントリを追加します(例:ko: { label: '한국어' })。src/content/docs/<locale>/の下に対応するディレクトリを作成します。- 手動で入力するか、以下で説明する翻訳ターゲットを使用します。
--noTranslation を渡さない限り、ジェネレーターは project.json に translate ターゲットを追加するため、以下を実行できます:
pnpm nx translate docs -- --allpnpm nx translate docs -- --languages jp,kopnpm nx translate docs -- --dry-runyarn nx translate docs -- --allyarn nx translate docs -- --languages jp,koyarn nx translate docs -- --dry-runnpx nx translate docs -- --allnpx nx translate docs -- --languages jp,konpx nx translate docs -- --dry-runbunx nx translate docs -- --allbunx nx translate docs -- --languages jp,kobunx nx translate docs -- --dry-run--all なしで実行すると、スクリプトは現在のブランチで最後の翻訳コミット以降に変更されたファイルのみを翻訳します。つまり、サイト全体を再翻訳することなく、すべてのドキュメント PR で安全に再実行できます。
ソースファイルが存在しなくなった翻訳は削除されるため、ページの名前変更や削除によって各ロケールに古いコピーが残ることはありません。
各翻訳はファイル全体として書き込まれます。エージェントにはソース、既存の翻訳、および変更内容の差分が与えられ、差分が変更しなかったセクションについては既存の文言を再利用します。そのため、差分が触れた散文のみが再翻訳され、コードブロックはソースからそのままコピーされます。
scripts/translate.config.json を編集して以下を変更します:
| フィールド | 目的 |
|---|---|
sourceLanguage | 翻訳元のロケール(デフォルトは en)。 |
targetLanguages | 翻訳先のロケール。デフォルトでは空です。例:["fr", "de", "es", "ja", "ko"]。 |
docsDir | プロジェクトルートからの相対的なドキュメントコンテンツディレクトリのパス。 |
include | 翻訳するファイルの Glob パターン(<docsDir>/<sourceLanguage> からの相対パス)。 |
exclude | スキップする Glob パターン。 |
modelId | 翻訳に使用する Bedrock モデル。 |
awsRegion | Bedrock クライアントが設定されている AWS リージョン。AWS_REGION 経由でも設定可能。 |
concurrency | 同時エージェント呼び出しの最大数。 |
translationCommitMessage | 翻訳コミットのコミットメッセージマーカー(デフォルトは docs: update translations)。 |
ロケール対応の内部リンク
Section titled “ロケール対応の内部リンク”ジェネレーターには、内部ドキュメントパスを現在のロケールに対して自動的に解決する Link コンポーネントが付属しているため、単一の情報源がすべての言語で正しい URL を生成します:
import Link from '@components/link.astro';
<Link path="guides/getting-started">Read the getting-started guide</Link>再利用可能なコンテンツフラグメントは src/content/docs/<locale>/snippets/ に配置されます。生成された Snippet コンポーネントは、現在のロケールに一致するスニペットを読み込みます:
import Snippet from '@components/snippet.astro';
<Snippet name="example" />CI の設定
Section titled “CI の設定”デフォルトでは CI ワークフローは生成されません。以下を行うワークフローを追加してください:
-
設定されたモデルで Bedrock
InvokeModelを呼び出す権限を持つ AWS 認証情報を設定します。 -
ソース言語のドキュメントに触れるプルリクエストで
translateターゲットを実行します:Terminal window pnpm nx translate docsTerminal window yarn nx translate docsTerminal window npx nx translate docsTerminal window bunx nx translate docs -
結果の翻訳を PR ブランチにコミットバックします。コミットメッセージは
scripts/translate.config.jsonのtranslationCommitMessage値(デフォルトはdocs: update translations)と一致する必要があります。これにより、後続の増分実行がベースラインコミットを検出し、それ以降に変更されたファイルのみを再翻訳できます。