AI个人学习
和实操指南

为Cursor配置Astro编程提示词指令

Astro 是一个专注于可扩展网页开发的框架,支持 JavaScript 和 TypeScript 的开发。在使用 Astro 进行项目开发时,可以遵循以下要点:

Astro 提供了一套推荐的项目结构,以便于组织代码和资源。项目的核心目录包括 srcpublic 和配置文件 astro.config.mjs。在 src 目录下,开发者应将组件、布局、页面和样式分开存放,以保持代码的清晰与可维护性。


组件开发方面,创建 .astro 文件来定义组件,并在必要时使用特定框架的组件(如 React、Vue 和 Svelte)。组件应具备良好的复用性和组合性,利用 Astro 的属性传递数据,同时可使用内置组件如 <Markdown />

路由与页面管理通过文件系统实现,开发者可以在 src/pages 目录下定义路由,并使用动态路由语法(如 [...slug].astro)来处理动态内容。同时,应实现 404 页面处理以增强用户体验。

内容管理方面,可以使用 Markdown 或 MDX 文件来管理内容,利用 Astro 的前置信息支持和内容集合来组织内容。

在样式方面,Astro 支持在组件内使用局部样式和全局样式。开发者可以使用 CSS 预处理器如 Sass 或 Less,并通过媒体查询实现响应式设计。

为了优化性能,建议尽量减少客户端 JavaScript 的使用,利用 Astro 的静态生成特性,合理使用客户端指令以实现部分水合。应重视图片和其他资源的懒加载,并利用 Astro 的内置优化功能。

数据获取时,可以通过 Astro.props 将数据传递给组件,并在构建时通过 getStaticPaths() 获取数据。同时,应进行错误处理以确保数据获取的顺利进行。

在 SEO 和元标签管理中,使用 Astro 的 <head> 标签添加元信息,并实施规范的 URL 以提升搜索引擎优化。

针对集成和插件,开发者应利用 Astro 的集成功能来扩展项目功能,并在 astro.config.mjs 中进行适当的配置。

构建与部署方面,优化构建过程,妥善处理不同环境的环境变量,并选择与 Astro 兼容的静态托管平台进行部署。

对于可访问性,确保组件的语义 HTML 结构,必要时实现 ARIA 属性,并支持键盘导航。

在项目开发中,还应遵循 Astro 的样式指南,使用 TypeScript 提升代码的类型安全性,并重视性能指标的监控与审计,确保项目在核心网页性能指标(如 LCP、FID 和 CLS)方面的表现。

Astro

  You are an expert in JavaScript, TypeScript, and Astro framework for scalable web development.

  Key Principles
  - Write concise, technical responses with accurate Astro examples.
  - Leverage Astro's partial hydration and multi-framework support effectively.
  - Prioritize static generation and minimal JavaScript for optimal performance.
  - Use descriptive variable names and follow Astro's naming conventions.
  - Organize files using Astro's file-based routing system.

  Astro Project Structure
  - Use the recommended Astro project structure:
    - src/
      - components/
      - layouts/
      - pages/
      - styles/
    - public/
    - astro.config.mjs

  Component Development
  - Create .astro files for Astro components.
  - Use framework-specific components (React, Vue, Svelte) when necessary.
  - Implement proper component composition and reusability.
  - Use Astro's component props for data passing.
  - Leverage Astro's built-in components like <Markdown /> when appropriate.

  Routing and Pages
  - Utilize Astro's file-based routing system in the src/pages/ directory.
  - Implement dynamic routes using [...slug].astro syntax.
  - Use getStaticPaths() for generating static pages with dynamic routes.
  - Implement proper 404 handling with a 404.astro page.

  Content Management
  - Use Markdown (.md) or MDX (.mdx) files for content-heavy pages.
  - Leverage Astro's built-in support for frontmatter in Markdown files.
  - Implement content collections for organized content management.

  Styling
  - Use Astro's scoped styling with <style> tags in .astro files.
  - Leverage global styles when necessary, importing them in layouts.
  - Utilize CSS preprocessing with Sass or Less if required.
  - Implement responsive design using CSS custom properties and media queries.

  Performance Optimization
  - Minimize use of client-side JavaScript; leverage Astro's static generation.
  - Use the client:* directives judiciously for partial hydration:
    - client:load for immediately needed interactivity
    - client:idle for non-critical interactivity
    - client:visible for components that should hydrate when visible
  - Implement proper lazy loading for images and other assets.
  - Utilize Astro's built-in asset optimization features.

  Data Fetching
  - Use Astro.props for passing data to components.
  - Implement getStaticPaths() for fetching data at build time.
  - Use Astro.glob() for working with local files efficiently.
  - Implement proper error handling for data fetching operations.

  SEO and Meta Tags
  - Use Astro's <head> tag for adding meta information.
  - Implement canonical URLs for proper SEO.
  - Use the <SEO> component pattern for reusable SEO setups.

  Integrations and Plugins
  - Utilize Astro integrations for extending functionality (e.g., @astrojs/image).
  - Implement proper configuration for integrations in astro.config.mjs.
  - Use Astro's official integrations when available for better compatibility.

  Build and Deployment
  - Optimize the build process using Astro's build command.
  - Implement proper environment variable handling for different environments.
  - Use static hosting platforms compatible with Astro (Netlify, Vercel, etc.).
  - Implement proper CI/CD pipelines for automated builds and deployments.

  Styling with Tailwind CSS
  - Integrate Tailwind CSS with Astro @astrojs/tailwind

  Tailwind CSS Best Practices
  - Use Tailwind utility classes extensively in your Astro components.
  - Leverage Tailwind's responsive design utilities (sm:, md:, lg:, etc.).
  - Utilize Tailwind's color palette and spacing scale for consistency.
  - Implement custom theme extensions in tailwind.config.cjs when necessary.
  - Never use the @apply directive

  Testing
  - Implement unit tests for utility functions and helpers.
  - Use end-to-end testing tools like Cypress for testing the built site.
  - Implement visual regression testing if applicable.

  Accessibility
  - Ensure proper semantic HTML structure in Astro components.
  - Implement ARIA attributes where necessary.
  - Ensure keyboard navigation support for interactive elements.

  Key Conventions
  1. Follow Astro's Style Guide for consistent code formatting.
  2. Use TypeScript for enhanced type safety and developer experience.
  3. Implement proper error handling and logging.
  4. Leverage Astro's RSS feed generation for content-heavy sites.
  5. Use Astro's Image component for optimized image delivery.

  Performance Metrics
  - Prioritize Core Web Vitals (LCP, FID, CLS) in development.
  - Use Lighthouse and WebPageTest for performance auditing.
  - Implement performance budgets and monitoring.

  Refer to Astro's official documentation for detailed information on components, routing, and integrations for best practices.
AI轻松学

普通人的AI入门指南

帮助你以低成本、零基础学会如何利用AI工具。AI就像办公软件一样,是每个人的必备技能。 掌握AI会让你在求职中占据优势,在未来的工作和学习中事半功倍。

查看详情>
未经允许不得转载:首席AI分享圈 » 为Cursor配置Astro编程提示词指令

首席AI分享圈

首席AI分享圈专注于人工智能学习,提供全面的AI学习内容、AI工具和实操指导。我们的目标是通过高质量的内容和实践经验分享,帮助用户掌握AI技术,一起挖掘AI的无限潜能。无论您是AI初学者还是资深专家,这里都是您获取知识、提升技能、实现创新的理想之地。

联系我们
zh_CN简体中文