astro – skill Tài liệu & Office cho agent AI
Xây dựng website tập trung nội dung với Astro: mặc định không dùng JS, kiến trúc islands, component đa framework và hỗ trợ Markdown/MDX.
Cài skill astro bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/astro-2c8cb.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /astro – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/astro-2c8cb.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $astro – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/astro-2c8cb.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /astro – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/astro-2c8cb.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /astro – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Astro Web Framework
Overview
Astro is a web framework designed for content-rich websites — blogs, docs, portfolios, marketing sites, and e-commerce. Its core innovation is the Islands Architecture: by default, Astro ships zero JavaScript to the browser. Interactive components are selectively hydrated as isolated "islands." Astro supports React, Vue, Svelte, Solid, and other UI frameworks simultaneously in the same project, letting you pick the right tool per component.
When to Use This Skill
- Use when building a blog, documentation site, marketing page, or portfolio
- Use when performance and Core Web Vitals are the top priority
- Use when the project is content-heavy with Markdown or MDX files
- Use when you want SSG (static) output with optional SSR for dynamic routes
- Use when the user asks about
.astrofiles,Astro.props, content collections, orclient:directives
How It Works
Step 1: Project Setup
npm create astro@latest my-site
cd my-site
npm install
npm run devAdd integrations as needed:
npx astro add tailwind # Tailwind CSS
npx astro add react # React component support
npx astro add mdx # MDX support
npx astro add sitemap # Auto sitemap.xml
npx astro add vercel # Vercel SSR adapterProject structure:
src/
pages/ ← File-based routing (.astro, .md, .mdx)
layouts/ ← Reusable page shells
components/ ← UI components (.astro, .tsx, .vue, etc.)
content/ ← Type-safe content collections (Markdown/MDX)
styles/ ← Global CSS
public/ ← Static assets (copied as-is)
astro.config.mjs ← Framework configStep 2: Astro Component Syntax
.astro files have a code fence at the top (server-only) and a template below:
---
// src/components/Card.astro
// This block runs on the server ONLY — never in the browser
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>
/* Scoped to this component automatically */
.card { border: 1px solid #eee; padding: 1rem; }
</style>Step 3: File-Based Pages and Routing
src/pages/index.astro → /
src/pages/about.astro → /about
src/pages/blog/[slug].astro → /blog/:slug (dynamic)
src/pages/blog/[...path].astro → /blog/* (catch-all)Dynamic route with 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 />The collection examples in Steps 3–4 and RSS use the legacy pre-Astro-5 content API (src/content/config.ts, post.slug, post.render()). Do not combine them with a new project unchanged: select the API for the installed major, migrate to content loaders and render() as required, and import getCollection in the dynamic page. Tailwind integration setup also depends on its major. See the [Astro 5 migration guide](https://docs.astro.build/en/guides/upgrade-to/v5/).
Step 4: Content Collections
Content collections give you type-safe access to Markdown and MDX files:
// 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>Step 5: Islands — Selective Hydration
By default, UI framework components render to static HTML with no JS. Use client: directives to hydrate:
---
import Counter from '../components/Counter.tsx'; // React component
import VideoPlayer from '../components/VideoPlayer.svelte';
---
<!-- Static HTML — no JavaScript sent to browser -->
<Counter initialCount={0} />
<!-- Hydrate immediately on page load -->
<Counter initialCount={0} client:load />
<!-- Hydrate when the component scrolls into view -->
<VideoPlayer src="/demo.mp4" client:visible />
<!-- Hydrate only when browser is idle -->
<Analytics client:idle />
<!-- Hydrate only on a specific media query -->
<MobileMenu client:media="(max-width: 768px)" />Step 6: Layouts
---
// 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 /> <!-- page content renders here -->
</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>Step 7: SSR Mode (On-Demand Rendering)
Enable SSR for dynamic pages by setting an adapter:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';
export default defineConfig({
output: 'static', // Astro 5+: prerender by default, opt routes out below
adapter: vercel(),
});Opt individual pages into SSR with export const prerender = false.
Examples
Example 1: Blog with RSS Feed
// 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}/`,
})),
});
}The subscribe handler is an incomplete application sketch: define addToNewsletter, opt this route out of prerendering in static mode, bound and validate JSON/email inputs, handle downstream errors and add consent, abuse and CSRF protections appropriate to the deployment before exposing it.
Example 2: API Endpoint (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 });
};Example 3: React Component as Island
// src/components/SearchBox.tsx
import { useState } from 'react';
export default function SearchBox() {
const [query, setQuery] = useState('');
const [results, setResults] = useState<Array<{ id: string; title: string }>>([]);
async function search(e: React.FormEvent) {
e.preventDefault();
const data = await fetch(`/api/search?q=${encodeURIComponent(query)}`).then(r => {
if (!r.ok) throw new Error(`Search failed: ${r.status}`);
return 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';
---
<!-- Hydrated immediately — this island is interactive -->
<SearchBox client:load />Best Practices
- ✅ Keep most components as static
.astrofiles — only hydrate what must be interactive - ✅ Use content collections for all Markdown/MDX content — you get type safety and auto-validation
- ✅ Prefer
client:visibleoverclient:loadfor below-the-fold components to reduce initial JS - ✅ Use
import.meta.envfor environment variables — prefix public vars withPUBLIC_ - ✅ Add
<ClientRouter />fromastro:transitionsfor smooth page navigation without a full SPA - ❌ Don't use
client:loadon every component — this defeats Astro's performance advantage - ❌ Don't put secrets in
.astrofrontmatter that gets used in client-facing temp
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- audio-transcriber – Chuyển đổi bản ghi âm thành tài liệu Markdown chuyên nghiệp với tóm tắt thông minh bằng…
- histolab – Trích xuất và tiền xử lý các ô (tile) ảnh mô học toàn lam (whole-slide) với Histolab…
- hads – Dùng khi viết tài liệu kỹ thuật vừa người đọc vừa mô hình AI đều đọc được, chuyển đổi…
- excel-author – Tạo sổ tính toán tài chính có thể kiểm toán ở chế độ headless bằng openpyxl.
- liteparse – Phân tích tài liệu và PDF cục bộ, trả về văn bản theo không gian kèm bounding box. Dùng…
- azure-ai-document-intelligence-dotnet – SDK Azure AI Document Intelligence cho .NET. Trích xuất văn bản, bảng và dữ liệu có cấu…
- azure-ai-document-intelligence-ts – Trích xuất văn bản, bảng và dữ liệu có cấu trúc từ tài liệu bằng mô hình dựng sẵn và mô…
- azure-ai-translation-document-py – SDK Azure AI Document Translation để dịch hàng loạt tài liệu và giữ nguyên định dạng…