Parsing Markdown Front Matter in Python
Our notes live in Markdown files with a little YAML on top. This script is how we turn them into something searchable.
Most of the improvement in a draft comes from cutting. We aim to remove a fifth of every piece on the second pass, and the reader never misses it.
import yaml
from pathlib import Path
def read_note(path: Path) -> tuple[dict, str]:
text = path.read_text(encoding="utf-8")
if not text.startswith("---\n"):
return {}, text
_, meta, body = text.split("---\n", 2)
return yaml.safe_load(meta) or {}, body.strip()
Deadlines help, but only when they are real. A deadline that everyone knows will slip is just a date on a calendar.
The first version of anything is a question, not an answer. Treating it that way makes feedback easier to give and much easier to hear.
Most of the improvement in a draft comes from cutting. We aim to remove a fifth of every piece on the second pass, and the reader never misses it.
Related posts
Shell Aliases That Save Us an Hour a Week
Git, rsync, and image tools, shortened to a few keystrokes.
Writing a Clean WordPress Shortcode
Attributes, escaping, and output buffering done the boring way.
A Small Go Server for Static Previews
Serve a folder, add caching headers, and ship a single binary.
Comments · 1
I watched the film again after reading this and noticed so many details I had missed.