feat: implement core markdown rendering pipeline
Add minimal e2e pipeline to transform content → HTML: - src/error.rs: Custom error types with thiserror - src/content.rs: YAML frontmatter parsing via gray_matter - src/render.rs: Markdown → HTML via pulldown-cmark - src/templates.rs: Maud templates for base layout and posts - src/main.rs: Pipeline orchestrator All 15 blog posts successfully rendered to public/blog/*/index.html. Added thiserror and walkdir dependencies. Added public/ and DepMap fragment to .gitignore and AGENTS.md.
This commit is contained in:
63
src/templates.rs
Normal file
63
src/templates.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
//! HTML templates using maud.
|
||||
|
||||
use crate::content::Frontmatter;
|
||||
use maud::{html, Markup, DOCTYPE};
|
||||
|
||||
/// Render a blog post with the base layout.
|
||||
pub fn render_post(frontmatter: &Frontmatter, content_html: &str) -> Markup {
|
||||
base_layout(
|
||||
&frontmatter.title,
|
||||
html! {
|
||||
article.post {
|
||||
header {
|
||||
h1 { (frontmatter.title) }
|
||||
@if let Some(ref date) = frontmatter.date {
|
||||
time.date { (date) }
|
||||
}
|
||||
@if let Some(ref desc) = frontmatter.description {
|
||||
p.description { (desc) }
|
||||
}
|
||||
@if !frontmatter.tags.is_empty() {
|
||||
ul.tags {
|
||||
@for tag in &frontmatter.tags {
|
||||
li { a href=(format!("/tags/{}/", tag)) { (tag) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
section.content {
|
||||
(maud::PreEscaped(content_html))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Base HTML layout wrapper.
|
||||
fn base_layout(title: &str, content: Markup) -> Markup {
|
||||
html! {
|
||||
(DOCTYPE)
|
||||
html lang="en" {
|
||||
head {
|
||||
meta charset="utf-8";
|
||||
meta name="viewport" content="width=device-width, initial-scale=1";
|
||||
title { (title) " | nrd.sh" }
|
||||
link rel="stylesheet" href="/style.css";
|
||||
}
|
||||
body {
|
||||
nav {
|
||||
a href="/" { "nrd.sh" }
|
||||
a href="/blog/" { "blog" }
|
||||
a href="/projects/" { "projects" }
|
||||
a href="/about/" { "about" }
|
||||
}
|
||||
main {
|
||||
(content)
|
||||
}
|
||||
footer {
|
||||
p { "© nrdxp" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user