WIP: tags support
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-05-02 14:37:32 +02:00
parent 76c682264f
commit 7dcff0b810
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 28 additions and 7 deletions

View file

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

View file

@ -73,6 +73,7 @@ struct Post {
url: String,
desc: Option<String>,
content: Option<String>,
tags: Option<Vec<String>>,
}
impl Post {
@ -122,11 +123,15 @@ fn get_posts(location: &str) -> Vec<Post> {
let root = parse_document(&arena, &text, &options);
let mut metadata = get_metadata(root);
// Always have a title
metadata.title = match metadata.title {
Some(title) => Some(title),
None => Some(file_without_ext.into()),
};
// No tags if the vec is empty
metadata.tags = metadata.tags.filter(|tags| !tags.is_empty());
metadata
}
Err(_) => FileMetadata {
@ -154,6 +159,7 @@ fn get_posts(location: &str) -> Vec<Post> {
}),
desc: file_metadata.description,
content: None,
tags: file_metadata.tags,
})
} else {
None
@ -195,18 +201,32 @@ fn get_post(post: &mut Option<File>, filename: String, name: String, url: String
*post = read_file(&format!("{blog_dir}/{filename}{ext}"));
let title = match post {
Some(data) => match &data.metadata.info.title {
let (title, tags) = match post {
Some(data) => (
match &data.metadata.info.title {
Some(text) => text,
None => &filename,
},
None => &filename,
match &data.metadata.info.tags {
Some(tags) => tags.clone(),
None => Vec::new(),
},
),
None => (&filename, Vec::new()),
};
Infos {
page_title: Some(format!("Post: {}", title)),
page_desc: Some(format!("Blog d'{name}")),
page_kw: Some(["blog", "blogging", "write", "writing"].join(", ")),
page_kw: Some(
vec!["blog", "blogging", "write", "writing"]
.iter()
.map(|&tag| tag.to_owned())
.chain(tags.into_iter())
.collect::<Vec<String>>()
.join(", "),
),
url,
}
}