Skip to content

Commit 5a063d0

Browse files
committed
feat: AI-Native support for Astro Strapi Blocks with Skills, AGENTS.md, and Cursor Rules
1 parent 8fb2095 commit 5a063d0

6 files changed

Lines changed: 144 additions & 1 deletion

File tree

.ai/AGENTS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Agent instructions (models, Cursor, and other tools)
2+
3+
The `.ai/` directory holds project-agnostic context for using **Astro Strapi Blocks** in **Astro + Strapi 5 (Blocks field)** projects. It is not tied to a single editor.
4+
5+
## Where to look
6+
7+
1. **Skill (workflow):** [astro-strapi-blocks/SKILL.md](./astro-strapi-blocks/SKILL.md) — passing `data`, `extend` / `overwrite`, overrides via `blocks`, and CMS type constraints.
8+
2. **Quick reference:** [astro-strapi-blocks/reference.md](./astro-strapi-blocks/reference.md) — theme paths and merge behavior.
9+
3. **API source of truth:** repository root `README.md` (props table, default theme, Astro examples, custom block prop types).
10+
11+
In **Cursor**, you can copy or symlink the skill folder to `.cursor/skills/astro-strapi-blocks/` if you want the skill in Cursor’s default skills location — the content is the same as under `.ai/astro-strapi-blocks/`.
12+
13+
## Code conventions
14+
15+
- Import `StrapiBlocks` from `@sensinum/astro-strapi-blocks`; pass **raw** block data from the Strapi response as `data={...}`.
16+
- Centralize themes in a single module with exports instead of duplicating large `theme` objects across files.
17+
- When overriding a block, follow the prop contract in the package README and use `renderPropertyClasses` / `getPropertyClass` wherever you mirror default class paths.
18+
19+
Do not put paths to private example repositories in public end-user documentation — patterns are described in general terms in the skill.

.ai/astro-strapi-blocks/SKILL.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
name: astro-strapi-blocks
3+
description: >-
4+
Integrates @sensinum/astro-strapi-blocks with Strapi 5 Blocks fields in Astro: wiring
5+
`data` from API responses, theming with `extend` and `overwrite`, and custom block
6+
components. Use when adding or editing Strapi block rendering, rich text zones, or
7+
`StrapiBlocks` / theme configuration.
8+
---
9+
10+
# Astro Strapi Blocks (Strapi 5 + Astro)
11+
12+
## Prereq
13+
14+
- `data` is **raw** Strapi 5 **Blocks** JSON: `StrapiBlockField` (array of blocks). Do not pre-stringify; pass the same shape the REST/GraphQL client returns.
15+
- Install `@sensinum/astro-strapi-blocks`, Astro per package requirements.
16+
17+
## Pass data into the component
18+
19+
1. In the Astro page, layout, or section component, receive the object that already includes the blocks field (e.g. from a loader, `getEntry`, or `fetch`).
20+
2. Pass that field: `data={entity.<blocksField>}`.
21+
3. If the field can be empty, guard the parent or accept empty array (the renderer maps over `data`).
22+
23+
**Anti-pattern:** building a new array by hand in the view unless the CMS is not the source of truth. Prefer one mapping from API types to your components at the data layer, then a single `data={...}`.
24+
25+
## Theme: `extend` vs `overwrite`
26+
27+
- **`extend`:** merges with the package default. String arrays (class lists) are **concatenated**; nested objects are merged. Use to tweak (e.g. add `prose` classes, brand links) while keeping default spacing where useful.
28+
- **`overwrite`:** replaces arrays at a given path; nested objects are still deep-merged, but any array you set **replaces** the default for that key. Use for a full design system look that should not retain Tailwind defaults from the built-in theme.
29+
30+
**Order of application (library behavior):** `overwrite` is applied first, then `extend` on the result. In a mixed `theme`, use `overwrite` to reset major sections and `extend` to add a few project-wide tokens.
31+
32+
**Lists and nesting:** for nested list markers, configure `list.indent.ordered` and `list.indent.unordered` as arrays: index 0 = top level, index 1 = first nested, etc. Use `getPropertyClass` and level when writing custom list markup that mirrors the default.
33+
34+
## Centralizing themes
35+
36+
- Export a default theme object (or factory) from a small module and import it in pages/sections. Keeps `StrapiBlocks` calls consistent.
37+
- If the same blocks must **look different** on different surfaces (e.g. on dark vs light, or in a card), return a **derived** theme from a base object (e.g. clone and adjust class strings for links/foreground). Avoid duplicating full theme trees in every `.astro` file.
38+
39+
## Custom block components (`blocks` prop)
40+
41+
Map built-in type keys to Astro components: `heading`, `paragraph`, `quote`, `list`, `code`, `image`.
42+
43+
Each override receives props consistent with the built-in block (see package README: `data`, `theme`, `class`, type-specific: `level`, `format`, `language`, `url`, `caption`, etc.).
44+
45+
1. Co-locate a custom `*.astro` file with your UI layer.
46+
2. Reuse `renderPropertyClasses` / `getPropertyClass` from the package for class paths that match the default theme structure.
47+
3. For text rich runs, follow how default blocks forward `data` to child item renderers (links, strong, etc.) so you do not drop formatting.
48+
49+
`StrapiBlockCustom` in the package wraps your component: your component receives the same prop contract as the default block for that type.
50+
51+
## New “block” types
52+
53+
Strapi 5 only emits the types the editor supports. This package **renders** the standard set. To add **custom** types you must add them in Strapi (e.g. custom field / plugin) and handle them in your own code path—`StrapiBlocks` only dispatches the built-in `type` values. If you need custom CMS blocks in one zone, use a **dynamic zone** in Strapi and a parent Astro switch that picks `StrapiBlocks` for rich-text fields and your components for other components.
54+
55+
## Checklist (new feature)
56+
57+
- [ ] Blocks field typed or asserted as `StrapiBlockField` / your shared API types.
58+
- [ ] `data` points at the unmodified blocks array from the response.
59+
- [ ] Theme: choose `extend`, `overwrite`, or both with clear intent.
60+
- [ ] Custom block: props match README; use theme helpers for class names.
61+
- [ ] Lists: if styling nested markers, set `list.indent` arrays to enough depth.
62+
63+
## Further reading
64+
65+
- [reference.md](reference.md) — path cheat sheet and `StrapiBlockUserTheme` shape.
66+
- Package `README.md` in the repository root for default theme table and copy-paste examples.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Reference: theme paths and types
2+
3+
## Theme merge semantics
4+
5+
- Objects: deep merge of keys.
6+
- Arrays of class strings: under **`extend`**, new classes append to defaults; under **`overwrite`**, the property’s array is replaced.
7+
8+
## Useful `renderPropertyClasses` / `getPropertyClass` paths
9+
10+
Top-level: `block` (root wrapper in default theme), then `heading`, `paragraph`, `quote`, `list`, `code`, `image`.
11+
12+
Examples:
13+
14+
- `['paragraph', 'block']`, `['paragraph', 'link']`
15+
- `['heading', 'h2']`, `['heading', 'content', 'strong']`
16+
- `['list', 'ordered']`, `['list', 'item']`, `['list', 'indent', 'unordered']` (for arrays indexed by depth, use `getPropertyClass` and subscript, not a single `renderPropertyClasses` on `indent` alone if you need per level)
17+
18+
## `StrapiBlockUserTheme` (conceptual)
19+
20+
- `extend?`: `DeepPartial` of the full resolved theme; arrays concat with defaults.
21+
- `overwrite?`: same shape; arrays replace at each leaf.
22+
23+
Import `StrapiBlockUserTheme` and related types from `@sensinum/astro-strapi-blocks` in consuming apps.
24+
25+
## Block map keys (override)
26+
27+
`heading` | `paragraph` | `quote` | `list` | `code` | `image`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
description: Astro + Strapi Blocks — StrapiBlocks, data, theme (extend/overwrite), custom blocks
3+
globs: "**/*.{astro,ts}"
4+
alwaysApply: false
5+
---
6+
7+
# Astro Strapi Blocks
8+
9+
- **Import:** `StrapiBlocks` from `@sensinum/astro-strapi-blocks`. **`data`:** raw Strapi 5 Blocks array (`StrapiBlockField`); use the same field the API already returns (e.g. `page.content`, `item.description`).
10+
11+
- **Theme:** `theme={{ extend: { … } }}` appends/merges with defaults; `overwrite` replaces class arrays at each path. Library order: `overwrite` first, then `extend`. For nested list markers, set `list.indent.ordered` / `unordered` as per-level class arrays; see package README.
12+
13+
- **Custom components:** `blocks={{ heading: MyHeading, … }}`. Each Astro override must match the block’s props (`data`, `theme`, and type-specific props in README). Use `renderPropertyClasses` / `getPropertyClass` from the package when reusing theme paths.
14+
15+
- **New CMS block types** need Strapi schema support; this component only dispatches built-in `type` values—combine with dynamic zones and parent switches for non-standard blocks.
16+
17+
- Deeper context: repository `.ai/astro-strapi-blocks/SKILL.md` and root `README.md`.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- 📋 [Requirements](#requirements)
2626
- 📦 [Installation](#installation)
2727
- 🚀 [Features](#features)
28+
- 🤖 [AI-Native support](#ai-native-support)
2829
- 🖥️ [Usage](#usage)
2930
- ⚙️ [Configuration](#configuration)
3031
- 🔧 [Development](#development)
@@ -60,6 +61,19 @@ npm install @sensinum/astro-strapi-blocks@latest
6061
- ⚡ Full control over block output
6162
- 🛠️ TypeScript support with full type definitions
6263

64+
## 🤖 AI-Native support
65+
66+
The repository includes agent-oriented materials so any coding assistant (IDE agents, CLIs, or models with project context) can apply consistent patterns for **integrating** `StrapiBlocks`, **theming** with `extend` / `overwrite`, **wiring Strapi data** into Astro, and **custom block** overrides.
67+
68+
| Resource | Path | Purpose |
69+
|----------|------|---------|
70+
| Agent overview | [`.ai/AGENTS.md`](.ai/AGENTS.md) | Entry point: where to look and how to use the skill in tooling |
71+
| Agent skill | [`.ai/astro-strapi-blocks/SKILL.md`](.ai/astro-strapi-blocks/SKILL.md) | Step-by-step workflow, checklist, and conventions |
72+
| Quick reference | [`.ai/astro-strapi-blocks/reference.md`](.ai/astro-strapi-blocks/reference.md) | Theme paths and merge behavior |
73+
| Cursor rules | [`.cursor/rules/astro-strapi-blocks.mdc`](.cursor/rules/astro-strapi-blocks.mdc) | Project rules for `.astro` / `.ts` when using Cursor |
74+
75+
**In another repo:** copy the `.ai/` folder (and optionally `.cursor/rules/`) into your app, or point your agent at this package’s `README` plus your local copy of `.ai/`. If you use **Cursor** and want the skill in the default skills location, symlink or copy `.ai/astro-strapi-blocks/` to `.cursor/skills/astro-strapi-blocks/`.
76+
6377
## 🖥️ Usage
6478

6579
```astro

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sensinum/astro-strapi-blocks",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Astro components for Strapi Block Field",
55
"keywords": [
66
"astro",

0 commit comments

Comments
 (0)