post listing with some more metadata
This commit is contained in:
@ -27,4 +27,4 @@ async fn main() {
|
||||
}
|
||||
|
||||
// TODO Port from env variable
|
||||
// TODO templating system
|
||||
// TODO displaying Image from netlify CDN
|
||||
|
@ -10,6 +10,7 @@ use super::post::PostMetadata;
|
||||
#[derive(Template)]
|
||||
#[template(path = "post_list.html")]
|
||||
pub struct PostListTemplate {
|
||||
pub title: String,
|
||||
pub posts: Vec<ParseResult<PostMetadata>>,
|
||||
pub tag: Option<String>,
|
||||
}
|
||||
@ -51,9 +52,12 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
|
||||
None => posts,
|
||||
};
|
||||
|
||||
Ok(PostListTemplate { posts, tag })
|
||||
Ok(PostListTemplate {
|
||||
title: "Posts".to_owned(),
|
||||
posts,
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
// TODO Do we want pagination or not? Ask designer
|
||||
// TODO How are we going to implement tags? The path extractor would have to make decision on wether we have a path or a blog post
|
||||
// TODO Refactor `?` with `.map_err`
|
||||
// TODO Do we want pagination or not? Ask designer/ We don't want itt
|
||||
// TODO when tags are true render different "see all post" message
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::path::Path;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use chrono::{DateTime, Utc};
|
||||
use gray_matter::{engine::YAML, Matter};
|
||||
@ -22,6 +24,7 @@ where
|
||||
pub struct ParseResult<Metadata> {
|
||||
pub body: String,
|
||||
pub metadata: Metadata,
|
||||
pub slug: String,
|
||||
}
|
||||
|
||||
pub async fn parse_post<'de, Metadata: DeserializeOwned>(
|
||||
@ -60,8 +63,16 @@ pub async fn parse_post<'de, Metadata: DeserializeOwned>(
|
||||
return StatusCode::INTERNAL_SERVER_ERROR;
|
||||
})?;
|
||||
|
||||
let filename = Path::new(path)
|
||||
.file_stem()
|
||||
.ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
.to_str()
|
||||
.ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
.to_owned();
|
||||
|
||||
return Ok(ParseResult {
|
||||
body,
|
||||
metadata: metadata.data,
|
||||
slug: filename,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user