Add publish option (#28)
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-05-02 13:05:42 +02:00
parent bc73c88562
commit 49392f5ca5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 23 additions and 18 deletions

View file

@ -14,6 +14,7 @@ pub struct FileMetadata {
pub link: Option<String>, pub link: Option<String>,
pub date: Option<Date>, pub date: Option<Date>,
pub description: Option<String>, pub description: Option<String>,
pub publish: Option<bool>,
} }
#[derive(Content)] #[derive(Content)]

View file

@ -106,7 +106,7 @@ fn get_posts(location: &str) -> Vec<Post> {
entries entries
.iter() .iter()
.map(|f| { .filter_map(|f| {
let _filename = f.file_name(); let _filename = f.file_name();
let filename = _filename.to_string_lossy(); let filename = _filename.to_string_lossy();
let file_without_ext = filename.split_at(filename.len() - 3).0; let file_without_ext = filename.split_at(filename.len() - 3).0;
@ -132,24 +132,28 @@ fn get_posts(location: &str) -> Vec<Post> {
}, },
}; };
Post { if let Some(true) = file_metadata.publish {
url: file_without_ext.into(), Some(Post {
title: file_metadata.title.unwrap(), url: file_without_ext.into(),
date: file_metadata.date.unwrap_or({ title: file_metadata.title.unwrap(),
let m = f.metadata().unwrap(); date: file_metadata.date.unwrap_or({
let date = std::convert::Into::<DateTime<Utc>>::into( let m = f.metadata().unwrap();
m.modified().unwrap_or(m.created().unwrap()), let date = std::convert::Into::<DateTime<Utc>>::into(
) m.modified().unwrap_or(m.created().unwrap()),
.date_naive(); )
.date_naive();
Date { Date {
day: date.day(), day: date.day(),
month: date.month(), month: date.month(),
year: date.year(), year: date.year(),
} }
}), }),
desc: file_metadata.description, desc: file_metadata.description,
content: None, content: None,
})
} else {
None
} }
}) })
.collect::<Vec<Post>>() .collect::<Vec<Post>>()