Skip to content

Adding Frontmatter Reader: Support summary card (OG. Twitter)#2321

Open
sspaeti wants to merge 4 commits intorust-lang:masterfrom
sspaeti:adding_frontmatter
Open

Adding Frontmatter Reader: Support summary card (OG. Twitter)#2321
sspaeti wants to merge 4 commits intorust-lang:masterfrom
sspaeti:adding_frontmatter

Conversation

@sspaeti
Copy link
Contributor

@sspaeti sspaeti commented Feb 20, 2024

See issues #1416 and specific description in my comment: #1416 (comment).

This works for my site dedp.online, but I'd appreciate some help to integrate it nicely. It's more hackable and hard-coded to these frontmatter I used:

struct FrontMatter {
    title: String,
    description: String,
    featured_image_url: String,
}

Would be nice to read them dynamically. Also, I'm not sure if I added it at the right points.

PS: I also tried to implement a preprocessor (see #1416 (comment)), but with this PR that one is not needed anymore. Also, I guess this should be integrated into mdBook, and can't be as Preprocessor only?

@szabgab
Copy link
Contributor

szabgab commented Apr 3, 2025

Hi, would you have time to rebase this to make it easier to review it, please?

Cargo.toml Outdated
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
topological-sort = "0.2.2"
gray_matter = "0.2" #Fronmatter
serde_yaml = "0.9"
Copy link
Contributor

Choose a reason for hiding this comment

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

serde_yaml was deprecated recently, please use serde_yml

use serde::Deserialize;

fn extract_frontmatter(content: &str) -> Option<&str> {
let start = content.find("---")? + 3; // Find the end of the first `---` + 3 to move past it
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that --- can appear anywhere in a regular markdown content, I'd restrict this to the case when the file starts with ---.

@rustbot

This comment has been minimized.

sspaeti and others added 3 commits February 12, 2026 20:38
Adds a `frontmatter` feature flag that parses YAML frontmatter from
chapter content and injects OG/Twitter meta tag data into the
Handlebars template context. All custom code is isolated in a single
module (frontmatter.rs) with 3 one-liner integration points behind
#[cfg(feature = "frontmatter")] for easy future upgrades.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@sspaeti
Copy link
Contributor Author

sspaeti commented Feb 12, 2026

@szabgab I finally updated my book, and therefore also rebased this branch.

The pre-processor https://github.com/sspaeti/mdbook-frontmatter-reader is no longer needed and has been integrated directly into frontmatter.rs (see changes).

Again, in my chapters in my mdbook, I can now add this in the frontmatter

---
title: "Business Intelligence, Semantic Layer, Modern OLAP, Data Virtualization"
description: "The history of semantic SQL"
featured_image_url: "https://www.dedp.online/images/features/ce-semantic-sql.png"
---

and that gets rendered in the HTML header:
image

FYI, if anyone is doing similar things - I added these hard-coded to my index.hbs as these do not change:

  Meta tag: <meta name="author" content="Simon Späti">
  Meta tag: <meta property="og:type" content="book">
  Meta tag: <meta name="twitter:card" content="summary_large_image"/>
  Meta tag: <meta name="twitter:creator" content="@sspaeti"/>

You can check the outcome in my book live at https://dedp.online/part-2/4-ce/semantic-layer-business-intelligence.html.

I hope that works, not sure if I have thought about everything, as this is my first mdBook submission, but it works great for my book for a long time :)

@sspaeti sspaeti requested a review from szabgab February 12, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants