diff --git a/axum_server/src/main.rs b/axum_server/src/main.rs index e01d7fd..926c570 100644 --- a/axum_server/src/main.rs +++ b/axum_server/src/main.rs @@ -27,4 +27,4 @@ async fn main() { } // TODO Port from env variable -// TODO templating system +// TODO displaying Image from netlify CDN diff --git a/axum_server/src/pages/post_list.rs b/axum_server/src/pages/post_list.rs index 3f95cad..b6d646b 100644 --- a/axum_server/src/pages/post_list.rs +++ b/axum_server/src/pages/post_list.rs @@ -10,6 +10,7 @@ use super::post::PostMetadata; #[derive(Template)] #[template(path = "post_list.html")] pub struct PostListTemplate { + pub title: String, pub posts: Vec>, pub tag: Option, } @@ -51,9 +52,12 @@ pub async fn render_post_list(tag: Option>) -> Result 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 diff --git a/axum_server/src/post_parser.rs b/axum_server/src/post_parser.rs index 2ec4c31..1d6d9a1 100644 --- a/axum_server/src/post_parser.rs +++ b/axum_server/src/post_parser.rs @@ -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 { 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, }); } diff --git a/axum_server/templates/base.html b/axum_server/templates/base.html index aeb584e..bd1df63 100644 --- a/axum_server/templates/base.html +++ b/axum_server/templates/base.html @@ -32,5 +32,6 @@ {% block content %} Placeholder {% endblock %} + {# footer, should be not dependant on the each individual handler but it should have it's own handler #} diff --git a/axum_server/templates/post_list.html b/axum_server/templates/post_list.html index 17ca242..1d2e2d4 100644 --- a/axum_server/templates/post_list.html +++ b/axum_server/templates/post_list.html @@ -1,4 +1,4 @@ -{% if posts.len() == 0 %} +{% extends "base.html" %} {% block content %} {% if posts.len() == 0 %}

You've found void in the space.

{% else %}

{# if filters.tags #} {# {filters.tags} #} Blog posts

@@ -12,10 +12,11 @@
    {% for post in posts %}
  • - {# #} {# - #} {{post.metadata.title}} + {% include "post_preview_card.html" %} {# + #} {# + #}
  • {% endfor %}
-{# #} +{# #} {% endblock %} diff --git a/axum_server/templates/post_preview_card.html b/axum_server/templates/post_preview_card.html new file mode 100644 index 0000000..72a95e4 --- /dev/null +++ b/axum_server/templates/post_preview_card.html @@ -0,0 +1,27 @@ + + +