Skip to content
jesusprodriguez.com

astro-static-site

Astro: sitio estático rápido

Conventions for Astro sites with static output: content collections, optimised images and islands only where they are needed.

plugin:
Web
stack:
Astro
task:
Build
version:
v1.0.0
updated:
size:
2.9 KB
read:
2 min
license:
CC-BY-4.0

When it fires

When creating .astro pages or components, defining collections or reviewing performance.

description: Construye y mantiene sitios estáticos en Astro 4/5 con content collections, imágenes optimizadas e islas mínimas. Úsala al crear páginas, componentes .astro, colecciones de contenido o al revisar el rendimiento de un sitio Astro.

  • Content collections
  • astro:assets
  • Islands and client:*
  • Core Web Vitals

How you ask for it

> Add a notes content collection to this Astro site, with its listing page.

Say this to the agent as it is: the skill loads itself from its description, you do not have to name it.

How to install one

/plugin marketplace add https://jesusprodriguez.com/skills/marketplace.json
/plugin install web@jprodriguez-toolkit

The native route, and the only one that updates itself: add the marketplace once and `/plugin marketplace update` brings in new versions. Skills get their own namespace (`azure-devops:azure-pr-review`).

The whole file

This is exactly what you download: no summaries, nothing trimmed.

Heads-up: the skill file itself is written in Spanish. Agents read it fine and answer in your language, but the prose below is not translated.

Astro: sitio estático rápido

Guía de trabajo para sitios Astro con salida estática. El objetivo por defecto es cero JavaScript en cliente salvo donde la interacción lo exija.

Reglas de oro

  1. HTML primero. Un componente .astro se renderiza en build. No añadas client:* hasta que exista una interacción real que lo necesite.
  2. client:visible antes que client:load. Si la isla está bajo el pliegue, no debe competir con el primer render.
  3. Imágenes siempre por astro:assets. <Image /> o <Picture /> con widths y sizes. Una imagen en public/ no se optimiza: solo va ahí lo que necesita una URL estable (favicon, PDF, robots.txt).
  4. Fuentes self-hosted vía @fontsource*, nunca CDN de Google: elimina una conexión de terceros y el FOUT asociado.

Content collections

Define el esquema en src/content/config.ts y deja que Zod valide en build:

import { defineCollection, z } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: ({ image }) => z.object({
    title:       z.string(),
    description: z.string(),
    pubDate:     z.coerce.date(),
    tags:        z.array(z.string()).default([]),
    draft:       z.boolean().default(false),
    heroImage:   image().optional(),
  }),
});

export const collections = { blog };
  • image() en el esquema es lo que permite optimizar la portada. Requiere que el fichero viva dentro de src/, no en public/.
  • Filtra los borradores en una única función (getPublishedPosts()), no en cada página: así no se escapa ninguno.

Rutas dinámicas

---
export async function getStaticPaths() {
  const posts = await getCollection('blog', ({ data }) => !data.draft);
  return posts.map((post) => ({ params: { slug: post.slug }, props: { post } }));
}
const { post } = Astro.props;
const { Content } = await post.render();
---
<Content />

Revisión de rendimiento

  • npm run build y comprueba que el bundle de _astro/*.js sea el esperado: si aparece un framework entero, hay una isla de más.
  • Toda imagen debe llegar al HTML con width y height para no provocar CLS.
  • El script anti-FOUC del tema va inline en el <head>, antes del CSS.

Errores frecuentes

SíntomaCausa habitual
La imagen no se optimizaEstá en public/ en vez de src/
CLS alto al cargarFalta width/height o aspect-ratio
Parpadeo de temaEl script del tema no es inline y bloqueante
Tags con URLs rotasFalta slugificar acentos y símbolos (.NET, C#)