add hide field in contact cards

This commit is contained in:
Mylloon 2024-11-10 11:14:27 +01:00
parent fa4d0ba7e8
commit e1448bd773
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 24 additions and 38 deletions

View file

@ -223,6 +223,7 @@ custom: Option<bool>
user: "Option<String>"
link: Option<String>
newtab: Option<bool>
hide: Option<bool>
description: >
Option<String>
---

View file

@ -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::<Vec<File>>();
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::<Vec<File>>();
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::<Vec<File>>();
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]

View file

@ -46,6 +46,7 @@ pub struct FileMetadataContact {
pub link: Option<String>,
pub newtab: Option<bool>,
pub description: Option<String>,
pub hide: Option<bool>,
}
/// Metadata for index page

View file

@ -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("<p>", "").replace("</p>", ""));
}
pub fn read(path: &str) -> Vec<File> {
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::<Vec<File>>()
}