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

1

Choose Your IDE

Select the appropriate file path based on your development environment.

2

Create the Rules File

Create the cursor rules file in your project:

Create file: .cursor/rules/astro.mdc

3

Add the Rules Configuration

Copy the rules configuration below into your newly created file.

4

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:visible or client:idle to 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