add draft in metadata

This commit is contained in:
Mylloon 2024-11-12 00:48:24 +01:00
parent d9f3d64c55
commit aaf228c32d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 14 additions and 12 deletions

View file

@ -171,6 +171,7 @@ title: Option<String>
date: Option<Date> date: Option<Date>
description: Option<String> description: Option<String>
publish: Option<bool> publish: Option<bool>
draft: Option<bool>
tags: Option<Vec<Tag>> tags: Option<Vec<Tag>>
--- ---
@ -180,7 +181,8 @@ Post content
- If no `title`, the filename will be used - If no `title`, the filename will be used
- `date` format is `day-month-year` - `date` format is `day-month-year`
- `publish` is default to false. When false, posts are hidden from index - `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 --> ### About <!-- omit in toc -->

View file

@ -12,6 +12,7 @@ pub struct FileMetadataBlog {
pub date: Option<Date>, pub date: Option<Date>,
pub description: Option<String>, pub description: Option<String>,
pub publish: Option<bool>, pub publish: Option<bool>,
pub draft: Option<bool>,
pub tags: Option<Vec<Tag>>, pub tags: Option<Vec<Tag>>,
pub toc: Option<bool>, pub toc: Option<bool>,
} }

View file

@ -59,16 +59,15 @@ impl Hash for Post {
} }
pub fn get_posts(location: &str) -> Vec<Post> { pub fn get_posts(location: &str) -> Vec<Post> {
let entries = std::fs::read_dir(location).map_or_else( std::fs::read_dir(location)
|_| vec![], .map_or_else(
|res| { |_| vec![],
res.flatten() |res| {
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md")) res.flatten()
.collect::<Vec<std::fs::DirEntry>>() .filter(|f| f.path().extension().map_or(false, |ext| ext == "md"))
}, .collect::<Vec<std::fs::DirEntry>>()
); },
)
entries
.iter() .iter()
.filter_map(|f| { .filter_map(|f| {
let fname = f.file_name(); 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 { Some(Post {
url: file_without_ext.into(), url: file_without_ext.into(),
title: file_metadata.title.unwrap(), title: file_metadata.title.unwrap(),