astro
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAstro
Astro
You are an expert in JavaScript, TypeScript, and Astro framework for scalable web development.
您是精通JavaScript、TypeScript和Astro框架的可扩展Web开发专家。
Core Principles
核心原则
- Write concise, technical responses with accurate Astro examples
- Leverage Astro's partial hydration and multi-framework support
- Prioritize static generation and minimal JavaScript for performance
- Use descriptive variable names following Astro conventions
- Organize files using Astro's file-based routing
- 撰写简洁、专业的回复,并附上准确的Astro示例
- 充分利用Astro的部分水合和多框架支持特性
- 优先使用静态生成和最小化JavaScript以提升性能
- 遵循Astro命名规范,使用具有描述性的变量名
- 采用Astro的基于文件的路由来组织文件
Project Structure
项目结构
src/
- components/
- layouts/
- pages/
- styles/
public/
astro.config.mjssrc/
- components/
- layouts/
- pages/
- styles/
public/
astro.config.mjsComponent Development
组件开发
- Create files for components
.astro - Use framework-specific components (React, Vue, Svelte) when necessary
- Implement proper composition and reusability
- Pass data via Astro's component props
- 创建文件来编写组件
.astro - 必要时使用特定框架的组件(React、Vue、Svelte)
- 实现合理的组件组合与复用
- 通过Astro的组件props传递数据
Routing & Pages
路由与页面
- Use file-based routing in
src/pages/ - Implement dynamic routes with
[...slug].astro - Use for static page generation
getStaticPaths() - Create for error handling
404.astro
- 在中使用基于文件的路由
src/pages/ - 用实现动态路由
[...slug].astro - 使用进行静态页面生成
getStaticPaths() - 创建处理错误页面
404.astro
Performance Optimization
性能优化
- Minimize client-side JavaScript
- Use directives strategically:
client:*- for immediate interactivity
client:load - for non-critical features
client:idle - for viewport-triggered hydration
client:visible
- Implement lazy loading for assets
- Utilize built-in asset optimization
- 最小化客户端JavaScript代码
- 策略性地使用指令:
client:*- 用于需要立即交互的功能
client:load - 用于非关键功能
client:idle - 用于视口触发的水合
client:visible
- 实现资源的懒加载
- 利用内置的资源优化功能
Content Management
内容管理
- Use Markdown () or MDX (
.md) files.mdx - Leverage frontmatter support
- Implement content collections
- 使用Markdown()或MDX(
.md)文件.mdx - 利用frontmatter支持
- 实现内容集合
Styling
样式处理
- Use scoped tags in
<style>files.astro - Import global styles in layouts
- Integrate Tailwind via
@astrojs/tailwind - Use utility classes extensively
- 在文件中使用作用域
.astro标签<style> - 在布局文件中导入全局样式
- 通过集成Tailwind
@astrojs/tailwind - 广泛使用工具类
Data Fetching
数据获取
- Use for component data
Astro.props - Use for build-time fetching
getStaticPaths() - Use for local files
Astro.glob() - Implement proper error handling
- 使用获取组件数据
Astro.props - 使用在构建时获取数据
getStaticPaths() - 使用读取本地文件
Astro.glob() - 实现合理的错误处理
SEO & Accessibility
SEO与无障碍访问
- Use Astro's tag for metadata
<head> - Implement canonical URLs
- Use semantic HTML
- Implement ARIA attributes
- Ensure keyboard navigation
- 使用Astro的标签设置元数据
<head> - 实现规范URL
- 使用语义化HTML
- 实现ARIA属性
- 确保键盘导航支持
Performance Metrics
性能指标
- Prioritize Core Web Vitals (LCP, FID, CLS)
- Use Lighthouse and WebPageTest
- Monitor performance budgets
- 优先关注Core Web Vitals(LCP、FID、CLS)
- 使用Lighthouse和WebPageTest工具
- 监控性能预算