From e8f69a34b1971249254f5b2ba18371c5e646b63a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 14 Nov 2024 03:28:50 +0100 Subject: [PATCH] correct url --- src/utils/routes/blog.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/utils/routes/blog.rs b/src/utils/routes/blog.rs index b960f18..8ea63b8 100644 --- a/src/utils/routes/blog.rs +++ b/src/utils/routes/blog.rs @@ -71,31 +71,33 @@ pub fn get_posts(location: &str) -> Vec { let filename = fname.to_string_lossy(); let file_without_ext = filename.split_at(filename.len() - 3).0; - let file_metadata = std::fs::read_to_string(format!("{location}/{filename}")) - .map_or_else( - |_| FileMetadataBlog { - title: Some(file_without_ext.into()), - ..FileMetadataBlog::default() - }, - |text| { - let arena = Arena::new(); + let file_metadata = std::fs::read_to_string(f.path()).map_or_else( + |_| FileMetadataBlog { + title: Some(file_without_ext.into()), + ..FileMetadataBlog::default() + }, + |text| { + let arena = Arena::new(); - let options = get_options(); - let root = parse_document(&arena, &text, &options); - let mut metadata = get(root, MType::Blog).blog.unwrap(); + let options = get_options(); + let root = parse_document(&arena, &text, &options); + let mut metadata = get(root, MType::Blog).blog.unwrap(); - // Always have a title - metadata.title = metadata - .title - .map_or_else(|| Some(file_without_ext.into()), Some); + // Always have a title + metadata.title = metadata + .title + .map_or_else(|| Some(file_without_ext.into()), Some); - metadata - }, - ); + metadata + }, + ); if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) { + let url = + f.path().to_string_lossy().strip_prefix(location).unwrap()[1..].to_owned(); + Some(Post { - url: file_without_ext.into(), + url: url[..url.len() - 3].to_owned(), title: file_metadata.title.unwrap(), date: file_metadata.date.unwrap_or({ let m = f.metadata().unwrap();