Communitygithub.com

Hermes Astro サイトビルダー

Astro 5 を使用して静的または SSR ウェブサイトを構築します。プロジェクトのセットアップ、レイアウト、ページ、統合(@astrojs/sitemap、@astrojs/mdx)、SEO(メタ、OG、JSON-LD、サイトマップ、robots.txt)、サイドバーナビゲーションとプログレスバーを備えた電子書籍/コンテンツレイアウト、Cloudflare Pages へのデプロイ、および既知の落とし穴(JSX 中括弧の解析、lightningcss、インポートパス)をカバーします。ユーザーが Astro サイトの構築、Cloudflare Pages へのデプロイ、Astro を使用した電子書籍/ドキュメントサイトの作成、またはポートフォリオ/ブログ/マーケティングサイトのスキャフォールディングを依頼した場合に使用します。

Hermes Astro サイトビルダー とは?

このスキルは、最新の Astro 5 フレームワークを使用して、本番環境対応の静的ウェブサイトを構築するための包括的なガイドです。ポートフォリオ、ブログ、マーケティングサイト、電子書籍プラットフォーム、ドキュメントサイトなど、さまざまなユースケースに対応しており、プロジェクトの初期化から Cloudflare Pages へのデプロイまでをカバーします。主な機能として、SEO 最適化(メタタグ、Open Graph、JSON-LD 構造化データ、サイトマップ、robots.txt)、@astrojs/sitemap や @astrojs/mdx などの統合、サイドバーナビゲーションと読書進捗バーを備えた再利用可能な電子書籍レイアウトが含まれます。また、Astro のスコープ付き CSS の問題、JSX 中括弧構文、インポートパスの深さ、lightningcss のバンドルなど、開発でよく遭遇する落とし穴についても詳しく説明しています。このスキルは、特に Cloudflare Pages へのデプロイと、電子書籍向けのスタンドアロン HTML ファイルの一貫性維持に重点を置いており、開発者が堅牢でスケーラブルな Astro サイトを迅速に構築できるように設計されています。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ahmadasrizalmi/hermes-skills/tree/HEAD/astro-site

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Astro サイトビルダー

Astro 5 を使用して、本番環境対応の静的ウェブサイトを構築します。ポートフォリオ、電子書籍プラットフォーム、ブログ、マーケティングサイト、ドキュメントをカバーします。

使用するタイミング

  • ユーザーが Astro サイト、ポートフォリオ、ブログの構築を依頼したとき
  • ユーザーが Cloudflare Pages にデプロイしたいとき
  • ユーザーがサイドバーナビゲーション付きの電子書籍/ドキュメントサイトを必要としているとき
  • ユーザーがサイトマップ、メタタグ、構造化データを使用した SEO 最適化済みの静的サイトを求めているとき
  • ユーザーが「Astro」「Cloudflare Pages」「JAMstack 静的サイト」に言及したとき

クイックスタート

# プロジェクトを作成
npm create astro@latest my-site -- --template minimal
cd my-site

# コア依存関係
npm install @astrojs/sitemap

# ビルドとプレビュー
npm run build    # 出力先 dist/
npm run preview  # ローカルプレビューサーバー

プロジェクト構成

project/
├── astro.config.mjs
├── package.json
├── tsconfig.json
├── public/
│   ├── robots.txt
│   └── _headers          # Cloudflare セキュリティヘッダー
├── src/
│   ├── layouts/
│   │   ├── BaseLayout.astro    # サイト全体のシェル(ヘッダー、フッター、SEO)
│   │   └── EbookLayout.astro   # コンテンツレイアウト(サイドバー、プログレスバー)
│   └── pages/
│       ├── index.astro         # ホームページ
│       ├── blog.astro
│       └── ebook/
│           ├── index.astro     # 電子書籍一覧
│           └── video-editing/
│               └── index.astro # 単一の電子書籍ページ
└── dist/                       # ビルド出力(これをデプロイ)

Astro 設定(Cloudflare 最適化)

// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  site: 'https://yourdomain.com',
  integrations: [sitemap()],
  prefetch: true,
  build: {
    inlineStylesheets: 'auto',  // 重要な CSS をインライン化して FCP を高速化
  },
});

SEO パターン(BaseLayout)

すべてのページが props を通じて完全な SEO を取得します:

---
export interface Props {
  title: string;
  description?: string;
  canonical?: string;
  image?: string;
  type?: string;  // 'website' | 'article'
}
---

<head> に含めるもの:

  • <title>(形式:ページタイトル | サイト名)
  • <meta name="description">
  • <link rel="canonical">
  • Open Graph タグ(og:type、og:title、og:description、og:image、og:url)
  • Twitter カードメタタグ
  • JSON-LD 構造化データ(Person、Organization、Article を適宜)
  • <meta name="robots" content="index, follow">

EbookLayout パターン

サイドバーナビゲーション付きの長文コンテンツ向け。完全な CSS については references/ebook-layout-css.md を参照してください。

機能

  • サイドバーナビゲーション — 固定左サイドバー、チャプターリンク、スクロール位置によるアクティブ状態の追跡
  • プログレスバー — 固定上部バー、読書進捗(0〜100%)を表示、グラデーション塗りつぶし(ティールからインディゴ)
  • トップに戻るボタン — 固定右下、400px スクロール後に表示
  • 著者クレジット — アバターサークル+名前/役割をコンテンツ下部に表示
  • コードブロック — ダーク背景(#1e293b)、グラデーション上部アクセントバー、等幅フォント、水平スクロール
  • テーブル — グラデーションヘッダー、交互の行色、ホバー効果、角丸ボーダー
  • コールアウトボックス — 4 種類:情報(青)、警告(琥珀色)、ヒント(緑)、危険(赤)、それぞれ SVG アイコン付き
  • 印刷スタイル — サイドバー/プログレス/ナビを非表示、コンテンツを展開、改ページルール
  • レスポンシブ — 3 つのブレークポイント(960px でサイドバー非表示、600px でコンパクト、モバイルでスタック)

CSS 戦略:<style slot="head"> での is:global

EbookLayout の CSS は is:global を使用する必要があります。これにより、スタイルがページコンポーネントからのスロットコンテンツに適用されます:

<style slot="head" is:global>
  /* ここにあるすべてのクラスがスロットコンテンツに適用される */
  .ebook-content h1 { ... }
  .callout { ... }
  .callout-info { ... }
</style>

is:global がないと、EbookLayout で定義された .callout-info などのクラスが、<EbookLayout> を使用するページコンポーネントの要素に適用されません。

EbookLayout の Props インターフェース

export interface Props {
  title: string;
  description?: string;
  chapters: { slug: string; title: string; number: number }[];
  currentSlug: string;
  ebookTitle: string;
  ebookDescription?: string;
  author?: string;  // デフォルトは 'Ahmad Asri Zalmi'
}

コンテンツページパターン

各電子書籍ページはチャプター配列を定義し、EbookLayout に渡します:

---
import EbookLayout from '../../../layouts/EbookLayout.astro';
const chapters = [
  { slug: 'index', title: 'Pendahuluan', number: 1 },
  { slug: 'topic-a', title: 'Topic A', number: 2 },
];
---
<EbookLayout title="ページタイトル" description="SEO 説明" chapters={chapters}
  currentSlug="ebook-slug" ebookTitle="電子書籍タイトル" ebookDescription="サブタイトル" author="著者名">
  <h1 id="index">ページタイトル</h1>
  <p class="ebook-subtitle">サブタイトルテキスト</p>
  <div class="ebook-meta">
    <!-- SVG ユーザーアイコン + 著者名 + SVG カレンダーアイコン + 年 -->
  </div>
  <!-- チャプター(slug に一致する h2 id) -->
</EbookLayout>

タイトル/ヘッダーブロック(必須)

<h1 id="index">タイトル</h1>
<p class="ebook-subtitle">サブタイトル</p>
<div class="ebook-meta">
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
  <span>著者名</span>
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-left:0.5rem"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
  <span>2026</span>
</div>

コールアウトボックス HTML(4 種類)

<!-- 情報(青 #3b82f6) -->
<div class="callout callout-info">
  <svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
  <div class="callout-content"><strong>タイトル</strong><p>内容。</p></div>
</div>

<!-- 警告(オレンジ #f59e0b) -->
<div class="callout callout-warning">
  <svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
  <div class="callout-content"><strong>タイトル</strong><p>内容。</p></div>
</div>

<!-- ヒント(緑 #22c55e) -->
<div class="callout callout-tip">
  <svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
  <div class="callout-content"><strong>タイトル</strong><p>内容。</p></div>
</div>

<!-- 危険(赤 #ef4444) -->
<div class="callout callout-danger">
  <svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
  <div class="callout-content"><strong>タイトル</strong><p>内容。</p></div>
</div>

リソースリンクセクション(電子書籍の最後)

<div class="resource-links">
  <h3>リソースとリンク</h3>
  <ul>
    <li>
      <a href="https://..." target="_blank" rel="noopener">リンクテキスト</a>
      <span class="desc">簡単な説明</span>
    </li>
  </ul>
</div>

set:html を使用したコードブロック

フロントマターでコード文字列を定義し、set:html でレンダリングします:

---
const code_example = `# シェルコマンド
npm run build`;
---
<pre><code set:html={code_example}></code></pre>

サイドバーのアクティブ状態(JS)

const navLinks = document.querySelectorAll('[data-nav-link]');
const headings = [];
navLinks.forEach(link => {
  const id = link.getAttribute('href').slice(1);
  const el = document.getElementById(id);
  if (el) headings.push({ el, link });
});
const updateActive = () => {
  let active = headings[0];
  for (const h of headings) {
    if (h.el.getBoundingClientRect().top <= 100) active = h;
  }
  navLinks.forEach(l => l.classList.remove('active'));
  if (active) active.link.classList.add('active');
};
window.addEventListener('scroll', updateActive, { passive: true });

コールアウトボックス HTML

<div class="callout callout-info">
  <svg class="callout-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/>
  </svg>
  <div class="callout-content">
    <strong>タイトル</strong>
    <p>ここにコンテンツテキスト。</p>
  </div>
</div>

インポートパスのルール

Astro は Vite のファイルベースルーティングを使用します。インポートパスはインポート元のファイルからの相対パスです:

ファイルの場所レイアウトのインポート元
src/pages/index.astro../layouts/BaseLayout.astro
src/pages/blog.astro../layouts/BaseLayout.astro
src/pages/ebook/index.astro../../layouts/BaseLayout.astro
src/pages/ebook/video-editing/index.astro../../../layouts/BaseLayout.astro

src/ からのディレクトリの深さを数えて、../ セグメントを決定します。

Cloudflare Pages デプロイメント

ビルド設定

設定値
フレームワークプリセットAstro
ビルドコマンドnpm run build
ビルド出力ディレクトリdist
Node.js バージョン18+(環境変数 NODE_VERSION で設定)

セキュリティヘッダー(public/_headers)

/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()

/assets/*
  Cache-Control: public, max-age=31536000, immutable

リダイレクト(public/_redirects)

/old-path  /new-path  301

Wrangler CLI デプロイ(直接アップロード)

# 最初にビルド
npm run build

# Cloudflare Pages にデプロイ
CLOUDFLARE_API_TOKEN=cfut_xxx CLOUDFLARE_ACCOUNT_ID=xxx \
  npx wrangler pages deploy dist --project-name=my-site --branch=main

# プレビューデプロイ(main 以外のブランチ)
npx wrangler pages deploy dist --project-name=my-site --branch=staging

スタンドアロン HTML の一貫性

スタンドアロンの HTML 電子書籍ファイルが public/ebook/ に存在する場合(Astro レイアウトをバイパス)、共有ヘッダー、サイドバー、カラースキーム、著者の説明を手動で注入する必要があります。完全なパターンについては references/standalone-html-consistency.md を参照してください。以下を含みます:

  • ロゴとナビゲーションを備えた注入済みスティッキーヘッダー(競合を避けるためにインライン CSS)
  • 固定サイドバーの上にヘッダーを追加する場合のサイドバーの top/height 調整
  • カラースキームの統一(CSS 変数、rgba、グラデーション — すべて更新する必要があります)
  • トップに戻るボタンの注入(CSS + HTML + JS)
  • パッチツール JS ネストの落とし穴(パッチ適用後は常に閉じ括弧を確認)
  • 著者の説明の一貫性チェックリスト

落とし穴

詳細な注意点については references/astro5-pitfalls.md を参照してください。概要:

  1. HTML 内の中括弧 — { と } は JSX 式です。コードブロックには set:html を使用してください。
  2. lightningcss がバンドルされていない — 個別にインストールするか、cssMinify: 'lightningcss' を使用しないでください。
  3. インポートパスの深さ — ディレクトリ構造と正確に一致させる必要があります。
  4. 絵文字なし — インライン SVG アイコンを使用してください(電子書籍ビルダースキルのユーザー設定)。
  5. set:html は void/自己終了タグまたはスロットでのみ使用可能 — set:html を使用する場合、子要素を持つことはできません。
  6. Astro のスコープ付き CSS — <style> 内のクラスはコンポーネントごとにスコープされます。共有クラスには <style is:global> または :global(.class) を使用してください。EbookLayout は、スタイルをスロットコンテンツに適用するために <style slot="head" is:global> を必ず使用する必要があります。
  7. data-astro-cid スコープの不一致 — BaseLayout の .container クラスは、ページコンポーネントの要素には適用されません。グローバルクラスが必要です:.container、.btn、.section、.grid-* など。
  8. JS クラス切り替えとスコープ付き CSS の組み合わせによるサイレント障害 — JavaScript が動的にクラスを追加/削除する場合(例:IntersectionObserver がスクロール時に .fade-in を追加)、Astro のスコープ付きセレクターと一致しません。Astro は .fade-in を .fade-in[data-astro-cid-xxxx] にスコープしますが、JS はプレーンな .fade-in クラスを追加します。症状: セクションが永遠に非表示(opacity:0)のままになります。修正方法: (a) アニメーションクラスに <style is:global> を使用する、(b) スコープ付きスタイルで :global(.fade-in) を使用する、(c) CSS アニメーションクラスを完全に削除してコンテンツをすぐにレンダリングさせる。オプション (c) は、アニメーションが重要でない SSR サイトにとって最も簡単です。詳細については、references/astro5-pitfalls.md の #9 を参照してください。
  9. スタンドアロン HTML のサイドバーオフセット — スタンドアロンの電子書籍 HTML ファイルにスティッキーヘッダーを注入する場合、常に固定サイドバーの top を 0 からヘッダーの高さ(約 56px)に調整し、height: calc(100vh - 56px) を設定してください。これを忘れると、サイドバーのコンテンツがヘッダーの後ろに隠れてしまいます。

アンチパターン

  • npm install lightningcss なしで cssMinify: 'lightningcss' を使用しないでください
  • <pre><code> ブロック内に {variable} を入れないでください — Astro が JSX として解析します
  • アイコンに絵文字を使用しないでください — インライン SVG を使用してください
  • SEO のために robots.txt とサイトマップを省略しないでください
  • モバイル対応のために <meta name="viewport"> を忘れないでください
  • サイト URL をハードコーディングしないでください — 設定から Astro.site を使用してください

関連スキル