Skip to content

Support YAML front matter in Markdown uploads#1

Closed
Said-MZ wants to merge 4 commits into
mainfrom
feat/markdown-front-matter
Closed

Support YAML front matter in Markdown uploads#1
Said-MZ wants to merge 4 commits into
mainfrom
feat/markdown-front-matter

Conversation

@Said-MZ

@Said-MZ Said-MZ commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Parse a leading ----delimited YAML front matter block off Markdown uploads before rendering (MarkdownDocument). title overrides the H1/filename fallback for the page <title>; description renders as a <meta name="description"> tag.
  • Malformed front matter, a non-mapping YAML block (e.g. a list), or its absence entirely all fall back to treating the whole file as plain Markdown body — front matter is never load-bearing for rendering.
  • Bonus fix: Procfile.dev's css process used Tailwind's --watch, which stops as soon as stdin closes — which Foreman does immediately for spawned processes — killing the whole mise run dev process group right after boot. Switched to --watch=always.

Test plan

  • bin/rails test test/models/markdown_document_test.rb (17 assertions covering strip/parse/title/description precedence, malformed and non-mapping front matter, and the "stray --- horizontal rule isn't mistaken for front matter" edge case) — all pass
  • bin/rails test test/models/paste_test.rb — all pass (no regression in the ingest path)
  • Manually rendered a sample Markdown file with front matter via rails runner and confirmed <title>/<meta description> are set correctly and the YAML block doesn't leak into the body
  • Verified mise run dev keeps all three Foreman processes (web/js/css) alive after the Procfile fix

🤖 Generated with Claude Code

Said-MZ added 2 commits July 13, 2026 22:34
Tailwind's --watch stops as soon as stdin closes, which Foreman does
immediately for spawned processes, so `mise run dev` exited the whole
process group right after boot. --watch=always keeps it running
regardless of stdin.
Parse a leading --- delimited YAML block off Markdown uploads before
rendering. `title` overrides the H1/filename fallback for the page
<title>, and `description` renders as a meta description tag. Malformed
or non-mapping front matter (or none at all) falls back to treating the
whole file as plain Markdown body, so nothing breaks rendering.
Copilot AI review requested due to automatic review settings July 13, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for YAML front matter in Markdown uploads so authors can set page metadata (HTML <title> and <meta name="description">) without affecting Markdown rendering, and adjusts the dev CSS watcher to stay alive under Foreman.

Changes:

  • Parse and strip a leading ----delimited YAML front matter block in MarkdownDocument, using title/description as metadata.
  • Add model tests covering front matter parsing, precedence rules, and fallback behavior for malformed/non-mapping YAML.
  • Update Procfile.dev CSS watcher invocation to use --watch=always to prevent premature shutdown.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/models/markdown_document.rb Adds front matter splitting/parsing and emits optional meta description tag during HTML rendering.
test/models/markdown_document_test.rb Introduces test coverage for front matter behavior and edge cases.
Procfile.dev Keeps the CSS watcher process alive under Foreman by switching Tailwind watch mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/models/markdown_document.rb Outdated
Said-MZ added 2 commits July 13, 2026 22:41
Psych::SyntaxError and Psych::DisallowedClass aren't the only failure
modes -- YAML aliases (&anchor/*alias) raise Psych::BadAlias or
Psych::AliasesNotEnabled, which weren't rescued and would break
rendering instead of falling back to plain Markdown body.

Co-authored-by: Copilot code review
Redundant with the broadened Psych::Exception rescue itself; not
worth the upkeep.
@Said-MZ

Said-MZ commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

Superseded by AliOsm#19, opened against the upstream repo instead of my fork.

@Said-MZ Said-MZ closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants