Today I learned how to strip out YAML frontmatter (--- … ---) from Markdown files using either Python or a shell script.
def remove_frontmatter(md_content): if md_content.startswith("---"): parts = md_content.split("---", 2) if len(parts) > 2: return parts[2].lstrip("\n") return md_content#!/bin/sh
if [ -f "$file" ] && head -n1 "$file" | grep -q '^---$'; then sed '1,/^---$/d' "$file" > "$file.tmp" && mv "$file.tmp" "$file"fiKey takeaway: Whether in Python or shell, the idea is the same—detect if the file starts with ---, then strip out everything up to the next ---.
