feat: allow subdirs in posts directory #86

Merged
Anri merged 4 commits from posts-subdir into main 2024-11-14 17:48:08 +01:00
Showing only changes of commit e8f69a34b1 - Show all commits

View file

@ -71,8 +71,7 @@ pub fn get_posts(location: &str) -> Vec<Post> {
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(
let file_metadata = std::fs::read_to_string(f.path()).map_or_else(
|_| FileMetadataBlog {
title: Some(file_without_ext.into()),
..FileMetadataBlog::default()
@ -94,8 +93,11 @@ pub fn get_posts(location: &str) -> Vec<Post> {
);
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();