Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Extract frontmatter metadata

Goal: Pull a document’s YAML frontmatter out as structured data, e.g. to read title/tags for a static-site index.

Prerequisites: None.

Query

.yaml | frontmatter
$ mq '.yaml | frontmatter' post.md

Input

---
title: Hello
tags: [a, b]
---

# Body

Output

{"title": "Hello", "tags": ["a", "b"]}

Notes

  • Grab a single field by chaining get("title"), e.g. .yaml | frontmatter | get("title") — a plain .title selector won’t work, since that’s a Markdown-node selector, not a dict-key accessor. Bracket access also works (frontmatter()["title"]), but only with the parentheses kept — frontmatter["title"] (no parens) tries to index the function itself and errors.
  • Combine with -F csv or -F json across multiple files to build a metadata index for a whole docs directory.