Skip to content

Extract frontmatter from markdown files#3

Merged
Tnixc merged 3 commits intomainfrom
claude/extract-frontmatter-from-md-011CUp6LcTCEyXd1P5sKqg1F
Nov 5, 2025
Merged

Extract frontmatter from markdown files#3
Tnixc merged 3 commits intomainfrom
claude/extract-frontmatter-from-md-011CUp6LcTCEyXd1P5sKqg1F

Conversation

@Tnixc
Copy link
Owner

@Tnixc Tnixc commented Nov 5, 2025

This pull request introduces first-class support for using YAML frontmatter in markdown files as a replacement for JSON data files, making it easier to manage and template content such as blog posts. The changes add TOML-based configuration for file ordering, automatic extraction of metadata from markdown frontmatter, and backwards compatibility with the legacy JSON workflow. Extensive documentation and an example project are also included to demonstrate the new workflow.

Frontmatter and Data Loading Improvements:

  • Added src/handlers/frontmatter.rs with functions to extract YAML frontmatter from markdown files and to load data from a list of markdown files specified in a TOML file. This enables automatic extraction of metadata for templating, with validation that each file contains a title field.
  • Updated the template data loading logic in src/handlers/templates.rs to first attempt loading data from a .data.toml file and associated markdown frontmatter, falling back to the legacy .data.json if TOML is not present.
  • Updated dependencies in Cargo.toml to include serde, serde_yaml, and toml for frontmatter and TOML parsing.

Markdown Processing Enhancements:

  • Modified src/handlers/entries.rs to strip YAML frontmatter from markdown content before rendering, ensuring that only the actual content is displayed on generated pages.

Documentation and Example Project:

  • Added a comprehensive example in example/README.md and supporting files to demonstrate the new frontmatter-based workflow, including a sample TOML configuration, markdown files with frontmatter, templates, and a styled index page. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated the main README.md to document the new recommended frontmatter workflow, including file structure, required fields, and auto-generated variables for templates.

These changes make it much easier and more flexible to manage content-driven sites, allowing users to use markdown files with frontmatter for both content and metadata, while maintaining compatibility with existing JSON-based data.

claude and others added 3 commits November 5, 2025 04:24
This adds support for extracting metadata from YAML frontmatter in markdown files,
eliminating the need to manually maintain data.json files.

Changes:
- Added serde, serde_yaml, and toml dependencies for parsing
- Created new frontmatter.rs handler to extract YAML frontmatter from .md files
- Modified templates.rs to support both .data.toml (new) and .data.json (legacy)
- TOML file lists which markdown files to include and in what order
- Frontmatter fields become template variables (${title}, ${date}, etc.)
- Auto-generates --entry-path, --result-path, and link fields
- Only 'title' field is required in frontmatter
- Updated README with comprehensive documentation for the new feature

File structure example:
  src/data/Posts/Posts.data.toml  # Lists files and order
  src/data/Posts/my-post.md       # Contains YAML frontmatter + content

The system falls back to .data.json if .data.toml doesn't exist, maintaining
backwards compatibility.
This commit fixes the issue where YAML frontmatter was being rendered as part
of the markdown content, and adds a complete working example demonstrating the
frontmatter feature.

Changes:
- Modified entries.rs to strip frontmatter before wrapping content in <markdown> tags
- Falls back to original content if frontmatter extraction fails (for files without frontmatter)
- Added comprehensive example directory with:
  - 3 sample blog posts with different frontmatter fields
  - TOML configuration file for file ordering
  - Template and frame files for rendering
  - Index page demonstrating the template system
  - Complete README with usage instructions

The example demonstrates:
- YAML frontmatter extraction
- TOML-based file ordering
- Auto-generated paths and links
- Template variable substitution
- Proper markdown rendering without frontmatter
- Backwards compatibility

Tested and verified: all files build correctly and frontmatter fields are
properly substituted in both list view and individual post pages.
Removed the 'Key Features Demonstrated' section from README.
@Tnixc Tnixc merged commit 39f942f into main Nov 5, 2025
1 check passed
@Tnixc Tnixc deleted the claude/extract-frontmatter-from-md-011CUp6LcTCEyXd1P5sKqg1F branch November 5, 2025 05:00
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