Adding Frontmatter Reader: Support summary card (OG. Twitter)#2321
Adding Frontmatter Reader: Support summary card (OG. Twitter)#2321sspaeti wants to merge 10 commits into
Conversation
|
Hi, would you have time to rebase this to make it easier to review it, please? |
| 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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Given that --- can appear anywhere in a regular markdown content, I'd restrict this to the case when the file starts with ---.
This comment has been minimized.
This comment has been minimized.
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>
4777b3a to
c3e8b00
Compare
This comment has been minimized.
This comment has been minimized.
|
@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 Again, in my chapters in my mdbook, I can now add this in the frontmatter and that gets rendered in the HTML header: FYI, if anyone is doing similar things - I added these hard-coded to my 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 :) Update: You also need to update |
This comment has been minimized.
This comment has been minimized.
|
I tried this PR but don't see any tags in the generated HTML. Do I have to modify Also, |
Yes, you need to add it to |
|
Shouldn't that be part of the PR? :) |
You are probably right! I just added it e944348 (not tested with plain mdBook yet, but should work, hopefully) - I didn't add it initially because I thought |
|
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. |
| <meta property="og:image" content="{{ og_image_url }}"> | ||
| <meta name="twitter:image" content="{{ og_image_url }}"/> | ||
| {{else}} | ||
| <meta property="og:image" content="https://avatars.githubusercontent.com/u/5430905?s=48&v=4"> |
There was a problem hiding this comment.
Please note I added the Rust logo from mdBook GitHub icon - please add or link a mdBook icon that you want to be shown on social media, if there's one. This is the image that will be shown when sharing online. As well as the line below twitter:image.

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:
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?