showcase projects loading and displaying

This commit is contained in:
2024-07-21 22:42:54 +02:00
parent 65bb29f36b
commit 1861a85e76
18 changed files with 215 additions and 48 deletions

View File

@ -8,11 +8,13 @@ use crate::{
site_header::HeaderProps,
},
featured_posts::get_featured_posts,
featured_projects::get_featured_projects,
post_parser::ParseResult,
tag_list::get_popular_blog_tags,
};
use super::post::PostMetadata;
use super::project::ProjectMetadata;
#[derive(Template)]
#[template(path = "index.html")]
@ -21,12 +23,14 @@ pub struct IndexTemplate {
header_props: HeaderProps,
blog_tags: Vec<String>,
featured_posts: Vec<ParseResult<PostMetadata>>,
featured_projects: Vec<ParseResult<ProjectMetadata>>,
}
pub async fn render_index() -> Result<IndexTemplate, StatusCode> {
let site_footer = tokio::spawn(render_site_footer());
let blog_tags = tokio::spawn(get_popular_blog_tags());
let featured_posts = tokio::spawn(get_featured_posts());
let featured_projects = tokio::spawn(get_featured_projects());
let blog_tags = blog_tags
.await
@ -40,10 +44,16 @@ pub async fn render_index() -> Result<IndexTemplate, StatusCode> {
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;
let featured_projects = featured_projects
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;
// TODO convert projects into cms
Ok(IndexTemplate {
site_footer,
header_props: HeaderProps::default(),
blog_tags,
featured_posts,
featured_projects,
})
}

View File

@ -3,3 +3,4 @@ pub mod contact;
pub mod index;
pub mod post;
pub mod post_list;
pub mod project;

View File

@ -12,6 +12,8 @@ use crate::{
post_parser::{deserialize_date, parse_post},
};
pub const BLOG_POST_PATH: &str = "../_posts/blog";
#[derive(Deserialize, Debug)]
pub struct PostMetadata {
pub layout: String,

View File

@ -11,7 +11,7 @@ use crate::{
post_parser::ParseResult,
};
use super::post::PostMetadata;
use super::post::{PostMetadata, BLOG_POST_PATH};
#[derive(Template)]
#[template(path = "post_list.html")]
@ -28,7 +28,7 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
let tag = tag.map(|Path(tag)| tag);
let site_footer = tokio::spawn(render_site_footer());
let mut post_list = get_post_list::<PostMetadata>().await?;
let mut post_list = get_post_list::<PostMetadata>(BLOG_POST_PATH).await?;
post_list.sort_by_key(|post| post.metadata.date);
post_list.reverse();

View File

@ -0,0 +1,12 @@
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct ProjectMetadata {
pub title: String,
pub description: String,
pub classification: String,
pub displayed: bool,
pub cover_image: Option<String>,
pub tags: Vec<String>,
pub featured: bool,
}