css and posts

This commit is contained in:
2026-01-25 20:28:13 -05:00
parent 552cad6b4a
commit a2ce84707d
18 changed files with 264 additions and 173 deletions

View File

@@ -16,10 +16,11 @@ fn load_posts() -> Result<HashMap<String, Post>, Error> {
let re_title = Regex::new(r#"#let\s+post_title\s*=\s*"([^"]*)""#).unwrap();
let re_summary = Regex::new(r#"#let\s+post_summary\s*=\s*"([^"]*)""#).unwrap();
let re_img = Regex::new(r#"#let\s+post_preview_image\s*=\s*"([^"]*)""#).unwrap();
let mut posts: HashMap<String, Post> = HashMap::new();
for dir in dirs {
let typst_path = dir?.path().join("post.typ");
let typst_path = dir.as_ref().unwrap().path().join("post.typ");
let typst = fs::read_to_string(typst_path).expect("Failed reading post");
let title = re_title.captures(&typst)
.expect("Post title not found")
@@ -27,16 +28,19 @@ fn load_posts() -> Result<HashMap<String, Post>, Error> {
let summary = re_summary.captures(&typst)
.expect("Post summary not found")
.get(1).unwrap().as_str().trim().to_string();
let img = dir?.path().join(
re_img.captures(&typst)
.expect("Post preview image not found")
.get(1).unwrap().as_str().trim().to_string());
let slug = title.clone().replace(" ", "-").to_lowercase();
posts.insert(
slug.clone(),
Post {
title: title.clone(),
slug: slug,
preview_image: "NA".to_string(),
preview_image: img.to_str().expect("Failed converting path to string").to_string(),
summary: summary,
render: Html(PostTemplate {
title: title,
content: typst_to_html(typst),
}.render().expect("Failed rendering post")),
}
@@ -48,7 +52,6 @@ fn load_posts() -> Result<HashMap<String, Post>, Error> {
#[derive(Template)]
#[template(path = "post.html")]
struct PostTemplate {
title: String,
content: String,
}
@@ -126,11 +129,7 @@ async fn main() {
.route("/", get(home_html))
.route("/posts", get(posts_html))
.route("/posts/{title}", get(|title| get_post(title, posts)))
.nest_service("/static", ServeDir::new("static"))
// .with_state(posts)
;
.nest_service("/static", ServeDir::new("static"));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
println!("Running on http://127.0.0.1:3000");