Communitygithub.com

Astro Web Framework(Astroウェブフレームワーク)

リクエストが Astro にマッチする場合に常に使用します。ゼロJS、アイランドアーキテクチャ、マルチフレームワークコンポーネント、Markdown/MDX サポートにより、コンテンツ中心のウェブサイトを構築します。

Astro Web Framework(Astroウェブフレームワーク) とは?

このスキルは、Astro Web Framework を使用してコンテンツ重視のウェブサイト(ブログ、ドキュメントサイト、ポートフォリオ、マーケティングサイト、eコマースなど)を構築するための包括的なガイドです。Astro の核となる革新は「アイランドアーキテクチャ」であり、デフォルトでブラウザに送信される JavaScript をゼロにし、対話型コンポーネントのみを選択的にハイドレーションします。React、Vue、Svelte、Solid などの様々なUIフレームワークを同一プロジェクト内で同時に使用できます。このスキールはプロジェクトのセットアップ、`.astro`ファイルの構文、ファイルベースルーティング、コンテンツコレクション、`client:`ディレクティブによるアイランドの選択的ハイドレーション、レイアウト、SSRモード、そしてRSSフィードやAPIエンドポイント、Reactコンポーネントをアイランドとして使用する実践的な例を詳細に解説しています。また、ベストプラクティス、セキュリティと安全性に関する注意事項、よくある落とし穴とその解決策、関連スキルリンクも提供します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/astro

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

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

ドキュメント

Astro Web Framework(Astroウェブフレームワーク) は何をしますか?

選別的読み取りルール

以下のファイルから始めてください:

  • references/senior-master-standard.md
  • references/usage-routing.md
  • references/quality-checklist.md

その後、ユーザーの実際のタスクに合致する継承されたドキュメント、スクリプト、アセット、または例のみをロードしてください。

概要

Astro は、ブログ、ドキュメント、ポートフォリオ、マーケティングサイト、eコマースなど、コンテンツが豊富なウェブサイト向けに設計されたウェブフレームワークです。その核となる革新はアイランドアーキテクチャです。デフォルトで Astro はブラウザにゼロの JavaScript を送信します。対話型コンポーネントは、分離された「アイランド」として選択的にハイドレーションされます。Astro は React、Vue、Svelte、Solid などのUIフレームワークを同一プロジェクト内で同時にサポートし、コンポーネントごとに適切なツールを選択できます。

このスキルを使用するタイミング

  • ブログ、ドキュメントサイト、マーケティングページ、ポートフォリオを構築するとき
  • パフォーマンスと Core Web Vitals が最優先事項であるとき
  • Markdown または MDX ファイルを含むコンテンツが多いプロジェクトの場合
  • SSG(静的)出力を希望し、動的ルートにはオプションで SSR を使用する場合
  • ユーザーが .astro ファイル、Astro.props、コンテンツコレクション、または client: ディレクティブについて質問したとき

仕組み

ステップ 1: プロジェクトのセットアップ

npm create astro@latest my-site
cd my-site
npm install
npm run dev

必要に応じてインテグレーションを追加します:

npx astro add tailwind        # Tailwind CSS
npx astro add react           # React コンポーネントサポート
npx astro add mdx             # MDX サポート
npx astro add sitemap         # 自動 sitemap.xml
npx astro add vercel          # Vercel SSR アダプター

プロジェクト構造:

src/
  pages/          ← ファイルベースルーティング (.astro, .md, .mdx)
  layouts/        ← 再利用可能なページシェル
  components/     ← UI コンポーネント (.astro, .tsx, .vue など)
  content/        ← 型安全なコンテンツコレクション (Markdown/MDX)
  styles/         ← グローバル CSS
public/           ← 静的アセット(そのままコピー)
astro.config.mjs  ← フレームワーク設定

ステップ 2: Astro コンポーネントの構文

.astro ファイルは上部にコードフェンス(サーバー専用)を持ち、その下にテンプレートがあります:

---
// src/components/Card.astro
// このブロックはサーバー上でのみ実行され、ブラウザでは決して実行されません
interface Props {
  title: string;
  href: string;
  description: string;
}

const { title, href, description } = Astro.props;
---

<article class="card">
  <h2><a href={href}>{title}</a></h2>
  <p>{description}</p>
</article>

<style>
  /* 自動的にこのコンポーネントにスコープされます */
  .card { border: 1px solid #eee; padding: 1rem; }
</style>

ステップ 3: ファイルベースのページとルーティング

src/pages/index.astro          → /
src/pages/about.astro          → /about
src/pages/blog/[slug].astro    → /blog/:slug (動的)
src/pages/blog/[...path].astro → /blog/* (キャッチオール)

getStaticPaths を使用した動的ルート:

---
// src/pages/blog/[slug].astro
export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map(post => ({
    params: { slug: post.slug },
    props: { post },
  }));
}

const { post } = Astro.props;
const { Content } = await post.render();
---

<h1>{post.data.title}</h1>
<Content />

ステップ 4: コンテンツコレクション

コンテンツコレクションは、Markdown および MDX ファイルへの型安全なアクセスを提供します:

// src/content/config.ts
import { z, defineCollection } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    date: z.coerce.date(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };
---
// src/pages/blog/index.astro
import { getCollection } from 'astro:content';

const posts = (await getCollection('blog'))
  .filter(p => !p.data.draft)
  .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
---

<ul>
  {posts.map(post => (
    <li>
      <a href={`/blog/${post.slug}`}>{post.data.title}</a>
      <time>{post.data.date.toLocaleDateString()}</time>
    </li>
  ))}
</ul>

ステップ 5: アイランド — 選択的ハイドレーション

デフォルトでは、UIフレームワークコンポーネントは JavaScript なしで静的 HTML にレンダリングされます。client: ディレクティブを使用してハイドレーションします:

---
import Counter from '../components/Counter.tsx';  // React コンポーネント
import VideoPlayer from '../components/VideoPlayer.svelte';
---

<!-- 静的 HTML — ブラウザに JavaScript は送信されません -->
<Counter initialCount={0} />

<!-- ページ読み込み時にすぐにハイドレーション -->
<Counter initialCount={0} client:load />

<!-- コンポーネントがビューポート内にスクロールされたときにハイドレーション -->
<VideoPlayer src="/demo.mp4" client:visible />

<!-- ブラウザがアイドル状態になったときにのみハイドレーション -->
<Analytics client:idle />

<!-- 特定のメディアクエリでのみハイドレーション -->
<MobileMenu client:media="(max-width: 768px)" />

ステップ 6: レイアウト

---
// src/layouts/BaseLayout.astro
interface Props {
  title: string;
  description?: string;
}
const { title, description = 'My Astro Site' } = Astro.props;
---

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title}</title>
    <meta name="description" content={description} />
  </head>
  <body>
    <nav>...</nav>
    <main>
      <slot />  <!-- ページコンテンツはここにレンダリングされます -->
    </main>
    <footer>...</footer>
  </body>
</html>
---
// src/pages/about.astro
import BaseLayout from '../layouts/BaseLayout.astro';
---

<BaseLayout title="About Us">
  <h1>About Us</h1>
  <p>Welcome to our company...</p>
</BaseLayout>

ステップ 7: SSR モード(オンデマンドレンダリング)

動的ページに対して SSR を有効にするには、アダプターを設定します:

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

export default defineConfig({
  output: 'hybrid',  // 'static' | 'server' | 'hybrid'
  adapter: vercel(),
});

export const prerender = false を使用して、個々のページを SSR にオプトインします。

例

例 1: RSS フィード付きブログ

// src/pages/rss.xml.ts
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';

export async function GET(context) {
  const posts = await getCollection('blog');
  return rss({
    title: 'My Blog',
    description: 'Latest posts',
    site: context.site,
    items: posts.map(post => ({
      title: post.data.title,
      pubDate: post.data.date,
      link: `/blog/${post.slug}/`,
    })),
  });
}

例 2: API エンドポイント (SSR)

// src/pages/api/subscribe.ts
import type { APIRoute } from 'astro';

export const POST: APIRoute = async ({ request }) => {
  const { email } = await request.json();

  if (!email) {
    return new Response(JSON.stringify({ error: 'Email required' }), {
      status: 400,
      headers: { 'Content-Type': 'application/json' },
    });
  }

  await addToNewsletter(email);
  return new Response(JSON.stringify({ success: true }), { status: 200 });
};

例 3: React コンポーネントをアイランドとして

// src/components/SearchBox.tsx
import { useState } from 'react';

export default function SearchBox() {
  const [query, setQuery] = useState('');
  const [results, setResults] = useState([]);

  async function search(e: React.FormEvent) {
    e.preventDefault();
    const data = await fetch(`/api/search?q=${query}`).then(r => r.json());
    setResults(data);
  }

  return (
    <form onSubmit={search}>
      <input value={query} onChange={e => setQuery(e.target.value)} />
      <button type="submit">Search</button>
      <ul>{results.map(r => <li key={r.id}>{r.title}</li>)}</ul>
    </form>
  );
}
---
import SearchBox from '../components/SearchBox.tsx';
---
<!-- すぐにハイドレーション — このアイランドはインタラクティブです -->
<SearchBox client:load />

ベストプラクティス

  • ✅ ほとんどのコンポーネントは静的 .astro ファイルとして保持し、インタラクティブである必要があるものだけをハイドレーションする
  • ✅ すべての Markdown/MDX コンテンツにコンテンツコレクションを使用する — 型安全性と自動検証が得られる
  • ✅ ファーストビュー以下のコンポーネントには client:load よりも client:visible を優先して使用し、初期 JS を削減する
  • ✅ 環境変数には import.meta.env を使用し、公開変数には PUBLIC_ プレフィックスを付ける
  • ✅ astro:transitions から <ViewTransitions /> を追加して、完全な SPA なしでスムーズなページナビゲーションを実現する
  • ❌ すべてのコンポーネントに client:load を使用しない — これにより Astro のパフォーマンス上の利点が損なわれる
  • ❌ 機密情報を、クライアント向けテンプレートで使用される .astro フロントマターに配置しない
  • ❌ 静的モードの動的ルートで getStaticPaths を省略しない — ビルドが失敗する

セキュリティと安全性に関する注意事項

  • .astro ファイルのフロントマターコードはサーバー側でのみ実行され、ブラウザに公開されることはありません。
  • 機密性の低い値にのみ import.meta.env.PUBLIC_* を使用してください。プライベート環境変数(PUBLIC_ プレフィックスなし)はクライアントに送信されることはありません。
  • SSR モードを使用する場合は、データベースクエリや API 呼び出しの前に、すべての Astro.request 入力を検証してください。
  • set:html を使用してレンダリングする前に、ユーザーが提供したコンテンツをすべてサニタイズしてください — 自動エスケープをバイパスします。

よくある落とし穴

  • 問題: React/Vue コンポーネントからの JavaScript がブラウザで実行されない 解決策: client: ディレクティブ(client:load、client:visible など)を追加してください — これがないと、コンポーネントは静的 HTML としてのみレンダリングされます。

  • 問題: 開発中にコンテンツを更新しても getStaticPaths データが古いまま 解決策: Astro の開発サーバーはコンテンツファイルを監視しています。content/config.ts への変更が反映されない場合は再起動してください。

  • 問題: Astro.props の型が any で、オートコンプリートが効かない 解決策: フロントマターで Props インターフェースまたは型を定義すると、Astro が自動的に推論します。

  • 問題: .astro コンポーネントの CSS が他のコンポーネントに漏れる 解決策: .astro の <style> タグ内のスタイルは自動的にスコープされます。子を意図的にターゲットにする場合にのみ :global() を使用してください。

関連スキル

  • @sveltekit — リアクティブなUIを備えたフルスタックフレームワークが必要な場合(Astro のコンテンツ重視に対して)
  • @nextjs-app-router-patterns — React ファーストのフルスタックフレームワークが必要な場合
  • @tailwind-patterns — Tailwind CSS で Astro サイトをスタイリングする
  • @progressive-web-app — Astro サイトに PWA 機能を追加する

制限事項

  • タスクが上記の範囲に明確に一致する場合にのみ、このスキルを使用してください。
  • 出力を環境固有の検証、テスト、または専門家によるレビューの代わりとして扱わないでください。
  • 必要な入力、権限、安全境界、または成功基準が不足している場合は、一旦停止して明確化を求めてください。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches 007: Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Agentfolio: Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Animejs Animation: Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astropy: Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Emotional ARC Designer: One sentence - what this skill does and when to invoke it

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Fixing Motion Performance: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches I18n Localization: Internationalization and localization patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Interactive Portfolio: Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches JQ: Expert jq usage for JSON querying, filtering, transformation, and pipeline integration.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Landing Page Generator: Generates high-converting Next.js/React landing pages with Tailwind CSS.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches LEX: Centralized ''Truth Engine'' for cross-jurisdictional legal context (US, EU, CA) and contract scaffolding.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Magic Animator: AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Makepad Animation: CRITICAL: Use for Makepad animation system.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs APP Router Patterns: Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Anhvu1107/all-agent-skill

ALWAYS use this when the user mentions Nextjs Best Practices, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on Nextjs Best Practices; scope: Next.js App Router principles. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output.

Anhvu1107/all-agent-skill

description: ALWAYS use this when the work is specifically about modern Next.js or React architecture, data flow, rendering strategy, routing, or performance-sensitive frontend behavior.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs Supabase Auth: Expert integration of Supabase Auth with Next.js App Router

Anhvu1107/all-agent-skill

ALWAYS use this when the task involves reading, extracting, splitting, merging, rotating, creating, validating, OCR-ing, form-filling, or otherwise producing or modifying PDF files.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches React Nextjs Development: React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when working with Remotion code, video compositions, rendering logic, timing, media assets, or React-based motion workflows.

関連スキル