Add publish option (#28)
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending
This commit is contained in:
parent
bc73c88562
commit
49392f5ca5
2 changed files with 23 additions and 18 deletions
|
@ -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)]
|
||||
|
|
|
@ -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>>()
|
||||
|
|
Loading…
Reference in a new issue