Skip to content

Commit

Permalink
added frontmatter parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Jan 28, 2024
1 parent ca12219 commit 2d2ecf0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ thiserror.workspace = true
pulldown-cmark.workspace = true
serde.workspace = true
slug = "0.1.5"
gray_matter = "0.2.6"

[features]
default = []
Expand Down
9 changes: 7 additions & 2 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::io::Read;

use gray_matter::{engine::TOML, Matter};
use leptos::{server, *};
use leptos_meta::*;
use leptos_router::*;
Expand Down Expand Up @@ -81,8 +82,12 @@ fn get_markdown_content(path: String) -> String {
.read_to_string(&mut input)
.expect("failed to read file");

let parser =
pulldown_cmark::Parser::new_ext(&input, pulldown_cmark::Options::all());
let matter = Matter::<TOML>::new().parse(&input);

let parser = pulldown_cmark::Parser::new_ext(
&matter.content,
pulldown_cmark::Options::all(),
);
let events = add_markdown_heading_ids(parser.into_iter().collect());
let mut html_output = String::new();
pulldown_cmark::html::push_html(&mut html_output, events.into_iter());
Expand Down
2 changes: 1 addition & 1 deletion content/posts/building-this-blog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Building this blog: A Space Odyssey"
title = "Building this blog: A Space Odyssey"
---

# Building this blog: A Space Odyssey
Expand Down

0 comments on commit 2d2ecf0

Please sign in to comment.