From 3d7cd8a7addd86b7a97a50821eb348345e0d427a Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 22 Dec 2021 01:06:39 -0500 Subject: Work for the day Post parsing, index page, navbar, CSS, blog listings There's something weird with the path matching that's making it miss the post view page in favor of the list view page. --- src/blog/post.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/blog/post.rs') diff --git a/src/blog/post.rs b/src/blog/post.rs index abe57aa..3c27690 100644 --- a/src/blog/post.rs +++ b/src/blog/post.rs @@ -1,7 +1,7 @@ use std::{cmp::Ordering, path::PathBuf}; use glob::glob; use color_eyre::eyre::{Result, Context, eyre}; -use tokio::fs; +use tokio::{fs}; use chrono::prelude::*; @@ -11,6 +11,7 @@ pub struct Post { pub front_matter: frontmatter::Data, pub body_html: String, pub date: DateTime, + pub link: String, } impl Ord for Post { @@ -46,6 +47,7 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result { Ok(Post { front_matter, body_html, + link, date } ) } @@ -55,7 +57,19 @@ pub async fn load(dir: &str) -> Result> { .filter_map(Result::ok) .map(|fname| read_post(dir, fname)); - Ok(Vec::new()) + let mut result: Vec = futures::future::join_all(futs) + .await + .into_iter() + .map(Result::unwrap) + .collect(); + + if result.len() == 0 { + Err(eyre!("No posts found")) + } else { + result.sort(); + result.reverse(); + Ok(result) + } } mod frontmatter { -- cgit v1.2.3