diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs index 20d7a50..f4a9435 100644 --- a/src/misc/markdown.rs +++ b/src/misc/markdown.rs @@ -14,6 +14,7 @@ pub struct FileMetadata { pub link: Option, pub date: Option, pub description: Option, + pub publish: Option, } #[derive(Content)] diff --git a/src/routes/blog.rs b/src/routes/blog.rs index 745248b..5ecd63a 100644 --- a/src/routes/blog.rs +++ b/src/routes/blog.rs @@ -106,7 +106,7 @@ fn get_posts(location: &str) -> Vec { entries .iter() - .map(|f| { + .filter_map(|f| { let _filename = f.file_name(); let filename = _filename.to_string_lossy(); let file_without_ext = filename.split_at(filename.len() - 3).0; @@ -132,24 +132,28 @@ fn get_posts(location: &str) -> Vec { }, }; - Post { - url: file_without_ext.into(), - title: file_metadata.title.unwrap(), - date: file_metadata.date.unwrap_or({ - let m = f.metadata().unwrap(); - let date = std::convert::Into::>::into( - m.modified().unwrap_or(m.created().unwrap()), - ) - .date_naive(); + if let Some(true) = file_metadata.publish { + Some(Post { + url: file_without_ext.into(), + title: file_metadata.title.unwrap(), + date: file_metadata.date.unwrap_or({ + let m = f.metadata().unwrap(); + let date = std::convert::Into::>::into( + m.modified().unwrap_or(m.created().unwrap()), + ) + .date_naive(); - Date { - day: date.day(), - month: date.month(), - year: date.year(), - } - }), - desc: file_metadata.description, - content: None, + Date { + day: date.day(), + month: date.month(), + year: date.year(), + } + }), + desc: file_metadata.description, + content: None, + }) + } else { + None } }) .collect::>()