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 date: Option<Date>,
pub description: Option<String>,
pub publish: Option<bool>,
}
#[derive(Content)]

View file

@ -106,7 +106,7 @@ fn get_posts(location: &str) -> Vec<Post> {
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> {
},
};
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::<DateTime<Utc>>::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::<DateTime<Utc>>::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::<Vec<Post>>()