add draft in metadata
This commit is contained in:
parent
d9f3d64c55
commit
aaf228c32d
3 changed files with 14 additions and 12 deletions
|
@ -171,6 +171,7 @@ title: Option<String>
|
|||
date: Option<Date>
|
||||
description: Option<String>
|
||||
publish: Option<bool>
|
||||
draft: Option<bool>
|
||||
tags: Option<Vec<Tag>>
|
||||
---
|
||||
|
||||
|
@ -180,7 +181,8 @@ Post content
|
|||
- If no `title`, the filename will be used
|
||||
- `date` format is `day-month-year`
|
||||
- `publish` is default to false. When false, posts are hidden from index
|
||||
but accessible, see [#30](https://git.mylloon.fr/Anri/mylloon.fr/issues/30)
|
||||
but accessible.
|
||||
- `draft` is default to false. When true, posts are hidden and unaccessible.
|
||||
|
||||
### About <!-- omit in toc -->
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct FileMetadataBlog {
|
|||
pub date: Option<Date>,
|
||||
pub description: Option<String>,
|
||||
pub publish: Option<bool>,
|
||||
pub draft: Option<bool>,
|
||||
pub tags: Option<Vec<Tag>>,
|
||||
pub toc: Option<bool>,
|
||||
}
|
||||
|
|
|
@ -59,16 +59,15 @@ impl Hash for Post {
|
|||
}
|
||||
|
||||
pub fn get_posts(location: &str) -> Vec<Post> {
|
||||
let entries = std::fs::read_dir(location).map_or_else(
|
||||
|_| vec![],
|
||||
|res| {
|
||||
res.flatten()
|
||||
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md"))
|
||||
.collect::<Vec<std::fs::DirEntry>>()
|
||||
},
|
||||
);
|
||||
|
||||
entries
|
||||
std::fs::read_dir(location)
|
||||
.map_or_else(
|
||||
|_| vec![],
|
||||
|res| {
|
||||
res.flatten()
|
||||
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md"))
|
||||
.collect::<Vec<std::fs::DirEntry>>()
|
||||
},
|
||||
)
|
||||
.iter()
|
||||
.filter_map(|f| {
|
||||
let fname = f.file_name();
|
||||
|
@ -97,7 +96,7 @@ pub fn get_posts(location: &str) -> Vec<Post> {
|
|||
},
|
||||
);
|
||||
|
||||
if file_metadata.publish == Some(true) {
|
||||
if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) {
|
||||
Some(Post {
|
||||
url: file_without_ext.into(),
|
||||
title: file_metadata.title.unwrap(),
|
||||
|
|
Loading…
Reference in a new issue