Astro Cursor Rules: Islands Architecture & Static Content
Comprehensive Astro cursor rules covering component islands, static generation, content collections, and hydration directives for fast, SEO-friendly sites.
Overview
Professional cursor rules for Astro that emphasize static-first architecture, component islands, and content collections. These rules help AI assistants generate clean, fast, and maintainable Astro code with complete context and sensible hydration strategies.
Note:
Optimizes component islands, static generation, and content collections with context-aware code generation aligned to modern Astro best practices.
Rules Configuration
.cursor/rules/astro.mdc
---
description: Enforces best practices for Astro development, focusing on context-aware code generation, static site generation, component islands, and file-based routing. Provides comprehensive guidelines for writing clean, efficient Astro code with proper context.
globs: **/*.{astro,mdx}
---
# Astro Best Practices
You are an expert in Astro development, static site generation, and related web technologies.
You understand modern Astro development practices, architectural patterns, and the importance of providing complete context in code generation.
## Astro-Specific Rules
Cursor rules in Astro provide intelligent navigation and manipulation capabilities designed specifically for Astro development. These rules help you work more efficiently with static site generation, component islands, and file-based routing.
### Component Navigation
- Navigate between static and interactive islands
- Jump to page and layout definitions
- Smart navigation between Markdown and MDX files
- Quick access to component imports
- Navigate through content collections
- Traverse client/server script blocks
### Smart Selection
- Select component script and template blocks
- Expand selection to include frontmatter
- Smart island component selection
- Content collection query selection
- Style block selection (scoped/global)
- Select hydration directives
### Code Manipulation
- Quick component insertion
- Automated frontmatter handling
- Content collection management
- Static/client directive optimization
- Style scope configuration
- Framework component integration
## Best Practices
- Use island-aware navigation
- Leverage static/dynamic patterns
- Utilize content collection features
- Navigate MDX efficiently
- Optimize component hydration
- Maintain client/server separation
## Examples
```javascript
// src/pages/blog/[...slug].astro
import { getCollection } from 'astro:content';
import Layout from '../layouts/BlogPost.astro';
import LikeButton from '../components/LikeButton';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map(post => ({
params: { slug: post.slug },
props: { post },
}));
}
const { post } = Astro.props;
---
<Layout title={post.data.title}>
<article>
<h1>{post.data.title}</h1>
<div class="content">
{post.body}
<LikeButton client:load />
</div>
</article>
</Layout>
Key Features
Component Islands
Ship minimal JS by hydrating only interactive components
Static-First
Prefer static generation for speed and reliability
Content Collections
Type-safe content management with astro:content
Multi-Framework Support
Use React/Vue/Svelte components where they add value
SEO-Friendly
Clean HTML, fast pages, and structured content
Testing Ready
Validate hydration and content rendering patterns
Installation
Choose Your IDE
Select the appropriate file path based on your development environment.
Create the Rules File
Create the cursor rules file in your project:
Create file: .cursor/rules/astro.mdc
Add the Rules Configuration
Copy the rules configuration below into your newly created file.
Start Building
Your AI assistant will now follow Astro best practices automatically.
Use Cases
Content Sites
Markdown/MDX blogs and docs with fast static pages
Hybrid Apps
Static shell with interactive islands where needed
Marketing Pages
SEO-focused pages with minimal JavaScript
Multi-Framework Sites
Combine React/Vue/Svelte components in Astro
Best Practices
Architecture
- Keep pages static; hydrate only interactive components
- Use layouts for shared structure and slots for composition
- Organize content with collections and type-check entries
Hydration
- Prefer
client:visibleorclient:idleto reduce JS - Avoid global client-side runtime unless necessary
- Defer non-critical scripts and lazy load images
Content Strategy
- Write descriptive alt text for images
- Keep paragraphs short and use active voice
- Avoid superlatives; use friendly, authoritative tone
Related Resources
Related Articles
Rust Cursor Rules: AI-Powered Development Best Practices
Cursor rules for Rust development enforcing ownership patterns, type safety, async/await practices, and clean code principles with AI assistance for production-ready code.
AI Rules Configuration: Enhancing Code Generation in IDEs
Explore comprehensive guidelines for configuring AI rules in modern IDEs. Learn to optimize AI assistants for enhanced code generation, streamlined development workflows, and consistent code quality across your projects.
React Cursor Rules: JSX, Hooks, and Component Patterns
Comprehensive React cursor rules covering component architecture, JSX patterns, hooks usage, accessibility, and testing for maintainable, performant applications.