---
title: "Frontmatter"
description: "How YAML frontmatter is parsed and which values become which types."
canonical: "https://www.qino.works/docs/guide/frontmatter"
---

# Frontmatter

> How YAML frontmatter is parsed and which values become which types.

Markdown, MDX, and `.markdown` files may start with a YAML block delimited by `---` lines. qino parses it with [js-yaml](https://github.com/nodeca/js-yaml) using the YAML 1.2 core schema, then validates the result against your schema. The body is added afterwards as `markdown`.

```md title="src/content/posts/hello-world.md"
---
title: Hello
draft: false
tags: [intro, markdown]
---

The body starts here.
```

## Shape

- The block must be a single mapping of field names to values.
- An empty or comment-only block yields `{}`.
- A scalar, a list, or several `---` documents at the top level is an error.
- Duplicate keys in a mapping are an error.
- A file without frontmatter is valid. The schema still runs, against `{}`.

## Scalar resolution

Unquoted values resolve by shape:

| YAML                                   | JavaScript           |
| -------------------------------------- | -------------------- |
| `true`, `false` (any case)             | boolean              |
| `null`, `~`, `Null`, or an empty value | `null`               |
| `42`, `-7`, `0x1F`, `0o17`, `017`      | number (`017` is 17) |
| `1.5`, `1e3`, `.inf`, `.nan`           | number               |
| `[a, b]` or a `-` list                 | array                |
| `{a: 1}` or an indented block          | plain object         |
| anything else                          | string               |

YAML 1.1 forms are not resolved. `yes`, `no`, `on`, `off`, `12:34:56`, `1_000`, and `0b11` stay strings. Quote a value to force a string, such as `zip: "01234"`.

## Dates

Dates are never converted. `2023-11-14` and `2023-11-14T12:34:56Z` arrive as strings. Validate them with `z.iso.date()` or coerce with `z.coerce.date()`. To receive a `Date` directly, tag the value:

```yaml title="src/content/posts/hello-world.md"
published: !!timestamp 2023-11-14
```

## Anchors, aliases, and merge keys

`&name` defines a node, `*name` reuses it, and `<<` copies a mapping's keys into another. Keys written directly win over merged ones:

```yaml title="src/content/posts/hello-world.md"
defaults: &defaults
  draft: false
  layout: post

article:
  <<: *defaults
  title: Hello
```

## Tags

The built-in `!!str`, `!!int`, `!!float`, `!!bool`, `!!null`, and `!!timestamp` tags work. Custom tags such as `!foo` and the YAML 1.1 collection tags `!!binary`, `!!set`, `!!omap`, and `!!pairs` raise an error.

## The body

Everything after the closing `---` is added to the entry as `markdown`, a string, after validation. An empty body is an empty string. It never reaches the schema, and declaring `markdown` in frontmatter is an error. See [Schemas](https://www.qino.works/docs/concepts/schemas).

## Camel case keys

Keys are returned as written. To rename them, for instance from `published_at` to `publishedAt`, use a schema transform. See [Entry pipeline](https://www.qino.works/docs/concepts/pipeline#example-camel-case-keys).
