css & post & site-structure

This commit is contained in:
2026-01-31 14:50:36 -05:00
parent a2ce84707d
commit 6cb6e73b14
8 changed files with 75 additions and 21 deletions

View File

@@ -14,31 +14,38 @@ fn load_posts() -> Result<HashMap<String, Post>, Error> {
let dirs = fs::read_dir("static/posts")?;
let re_title = Regex::new(r#"#let\s+post_title\s*=\s*"([^"]*)""#).unwrap();
let re_slug = Regex::new(r#"#let\s+post_slug\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 re_title = Regex::new("(?m)^=+ (.*)").unwrap();
let mut posts: HashMap<String, Post> = HashMap::new();
for dir in dirs {
let typst_path = dir.as_ref().unwrap().path().join("post.typ");
let dir_path = dir.as_ref().unwrap().path();
let typst_path = dir_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")
.expect(format!("Post title not found in {}", dir_path.to_str().unwrap()).as_str())
.get(1).unwrap().as_str().trim().to_string() ;
println!("{}", title);
let slug = re_slug.captures(&typst)
.expect("Post slug not found")
.get(1).unwrap().as_str().trim().to_string();
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();
let img_path = dir?.path().join(
re_img.captures(&typst)
.expect("Post preview image not found")
.get(1).unwrap().as_str().trim().to_string()
).to_str().expect("Failed converting path to string").to_string();
posts.insert(
slug.clone(),
Post {
title: title.clone(),
slug: slug,
preview_image: img.to_str().expect("Failed converting path to string").to_string(),
title: title,
preview_image: img_path,
summary: summary,
render: Html(PostTemplate {
content: typst_to_html(typst),
@@ -128,7 +135,7 @@ async fn main() {
let site: Router = Router::new()
.route("/", get(home_html))
.route("/posts", get(posts_html))
.route("/posts/{title}", get(|title| get_post(title, posts)))
.route("/posts/{slug}", get(|slug| get_post(slug, posts)))
.nest_service("/static", ServeDir::new("static"));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();