From e1448bd77363247fcaae6922a812dab77b158689 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 10 Nov 2024 11:14:27 +0100 Subject: [PATCH] add `hide` field in contact cards --- Documentation.md | 1 + src/routes/contact.rs | 41 ++++--------------------------------- src/utils/metadata.rs | 1 + src/utils/routes/contact.rs | 19 ++++++++++++++++- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/Documentation.md b/Documentation.md index b527524..2eb381e 100644 --- a/Documentation.md +++ b/Documentation.md @@ -223,6 +223,7 @@ custom: Option user: "Option" link: Option newtab: Option +hide: Option description: > Option --- diff --git a/src/routes/contact.rs b/src/routes/contact.rs index 48490d1..f1b0d2d 100644 --- a/src/routes/contact.rs +++ b/src/routes/contact.rs @@ -1,6 +1,5 @@ use actix_web::{get, routes, web, HttpRequest, Responder}; use cached::proc_macro::once; -use glob::glob; use ramhorns::Content; use crate::{ @@ -10,7 +9,7 @@ use crate::{ markdown::File, metadata::MType, misc::{make_kw, read_file, Html}, - routes::contact::{find_links, remove_paragraphs}, + routes::contact::{find_links, read, remove_paragraphs}, }, }; @@ -87,41 +86,9 @@ fn build_page(config: Config) -> String { // Get about let about = read_file(format!("{contacts_dir}/about.md"), MType::Generic); - let socials_dir = "socials"; - let mut socials = glob(&format!("{contacts_dir}/{socials_dir}/*{ext}")) - .unwrap() - .map(|e| { - read_file( - e.unwrap().to_string_lossy().to_string(), - MType::Contact, - ) - .unwrap() - }) - .collect::>(); - - let forges_dir = "forges"; - let mut forges = glob(&format!("{contacts_dir}/{forges_dir}/*{ext}")) - .unwrap() - .map(|e| { - read_file( - e.unwrap().to_string_lossy().to_string(), - MType::Contact, - ) - .unwrap() - }) - .collect::>(); - - let others_dir = "others"; - let mut others = glob(&format!("{contacts_dir}/{others_dir}/*{ext}")) - .unwrap() - .map(|e| { - read_file( - e.unwrap().to_string_lossy().to_string(), - MType::Contact, - ) - .unwrap() - }) - .collect::>(); + let mut socials = read(&format!("{contacts_dir}/socials/*{ext}")); + let mut forges = read(&format!("{contacts_dir}/forges/*{ext}")); + let mut others = read(&format!("{contacts_dir}/others/*{ext}")); // Remove paragraphs in custom statements [&mut socials, &mut forges, &mut others] diff --git a/src/utils/metadata.rs b/src/utils/metadata.rs index a509d96..7a78ba8 100644 --- a/src/utils/metadata.rs +++ b/src/utils/metadata.rs @@ -46,6 +46,7 @@ pub struct FileMetadataContact { pub link: Option, pub newtab: Option, pub description: Option, + pub hide: Option, } /// Metadata for index page diff --git a/src/utils/routes/contact.rs b/src/utils/routes/contact.rs index e0d25d2..0d9c603 100644 --- a/src/utils/routes/contact.rs +++ b/src/utils/routes/contact.rs @@ -1,7 +1,8 @@ use cached::proc_macro::once; +use glob::glob; use std::fs::read_to_string; -use crate::utils::markdown::File; +use crate::utils::{markdown::File, metadata::MType, misc::read_file}; /// Contact node #[derive(Clone, Debug)] @@ -48,3 +49,19 @@ pub fn remove_paragraphs(list: &mut [File]) { list.iter_mut() .for_each(|file| file.content = file.content.replace("

", "").replace("

", "")); } + +pub fn read(path: &str) -> Vec { + glob(path) + .unwrap() + .map(|e| read_file(e.unwrap().to_string_lossy().to_string(), MType::Contact).unwrap()) + .filter(|f| { + !f.metadata + .info + .contact + .clone() + .unwrap() + .hide + .unwrap_or_default() + }) + .collect::>() +}