Usar YAML frontmatter para documento metadata
Frontmatter es YAML metadata at el arriba de un Markdown archivo, delimited por ---. Común en static site generators (Astro, Hugo, Jekyll) para página metadata.
- 1
Frontmatter is a YAML block at the top of a file, delimited by --- on the first line and before the content. It contains metadata (title, date, tags, layout) that is parsed separately from the Markdown body. Static site generators use it to drive templates, routing, and collections.
- 2 Convertidor YAML →
Analizar the frontmatter YAML to verify valid syntax. Common fields: title (string), date (ISO 8601), tags (array), draft (boolean), layout (string). YAML errors in frontmatter will prevent the page from building — validate early.
- 3 Convertidor de Markdown a HTML →
Analizar the Markdown body (after the frontmatter) to HTML. The frontmatter and body are processed separately: YAML metadata for templates, Markdown for content. This separation enables data-driven page generation.
- 4
Best practices: use consistent field names across all pages, use ISO 8601 dates (2024-01-15 or 2024-01-15T10:30:00Z), use arrays for tags and categories, use booleans for draft/featured flags. Define a schema (Zod, JSON Schema) and validate at build time to catch missing or invalid fields.
Preguntas frecuentes
- YAML vs TOML vs JSON frontmatter?
- YAML is the most common (Hugo, Jekyll, Astro) — human-readable, supports comments. TOML is used by some tools (Zola) — stricter, less ambiguous. JSON is less common but universally parseable. Use YAML for most cases; use TOML if you want strict parsing.
- Can frontmatter contain Markdown?
- Yes, but it must be quoted or use YAML block scalars (| for literal, > for folded). For example: description: | This is a **long** description with _Markdown_. Parse this field as Markdown in your template.