contact genericity

This commit is contained in:
Mylloon 2024-01-25 18:28:21 +01:00
parent 9558202a46
commit d51afcdcf6
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 14 additions and 4 deletions

View file

@ -13,6 +13,8 @@ use crate::{
template::{Infos, NavBar}, template::{Infos, NavBar},
}; };
const CONTACT_DIR: &str = "contacts";
pub fn pages(cfg: &mut web::ServiceConfig) { pub fn pages(cfg: &mut web::ServiceConfig) {
// Here define the services used // Here define the services used
let routes = |route_path| { let routes = |route_path| {
@ -76,7 +78,7 @@ fn find_links(directory: String) -> Vec<ContactLink> {
#[get("/{service}/{scope}")] #[get("/{service}/{scope}")]
async fn service_redirection(config: web::Data<Config>, req: HttpRequest) -> impl Responder { async fn service_redirection(config: web::Data<Config>, req: HttpRequest) -> impl Responder {
let info = req.match_info(); let info = req.match_info();
let link = find_links(format!("{}/contacts", config.locations.data_dir)) let link = find_links(format!("{}/{}", config.locations.data_dir, CONTACT_DIR))
.iter() .iter()
// Find requested service // Find requested service
.filter(|&x| x.service == *info.query("service")) .filter(|&x| x.service == *info.query("service"))
@ -105,6 +107,7 @@ async fn service_redirection(config: web::Data<Config>, req: HttpRequest) -> imp
#[derive(Content, Debug)] #[derive(Content, Debug)]
struct NetworksTemplate { struct NetworksTemplate {
navbar: NavBar, navbar: NavBar,
about: Option<File>,
socials_exists: bool, socials_exists: bool,
socials: Vec<File>, socials: Vec<File>,
@ -123,9 +126,15 @@ fn remove_paragraphs(list: &mut [File]) {
#[once(time = 60)] #[once(time = 60)]
fn build_page(config: Config) -> String { fn build_page(config: Config) -> String {
let contacts_dir = format!("{}/contacts", config.locations.data_dir); let contacts_dir = format!("{}/{}", config.locations.data_dir, CONTACT_DIR);
let ext = ".md"; let ext = ".md";
// Get about
let about = read_file(
&format!("{}/about.md", contacts_dir),
TypeFileMetadata::Generic,
);
let socials_dir = "socials"; let socials_dir = "socials";
let mut socials = glob(&format!("{contacts_dir}/{socials_dir}/*{ext}")) let mut socials = glob(&format!("{contacts_dir}/{socials_dir}/*{ext}"))
.unwrap() .unwrap()
@ -156,6 +165,8 @@ fn build_page(config: Config) -> String {
contact: true, contact: true,
..NavBar::default() ..NavBar::default()
}, },
about,
socials_exists: !socials.is_empty(), socials_exists: !socials.is_empty(),
socials, socials,

View file

@ -8,9 +8,8 @@
<header>{{>navbar.html}}</header> <header>{{>navbar.html}}</header>
<main> <main>
<h1>Contact</h1> <h1>Contact</h1>
<p>Je suis présent relativement partout sur internet 😸</p> {{#data}}{{#about}} {{&content}} {{/about}} {{#socials_exists}}
{{#data}} {{#socials_exists}}
<h2>Réseaux sociaux</h2> <h2>Réseaux sociaux</h2>
<ul> <ul>
{{#socials}} {{>contact/element.html}} {{/socials}} {{#socials}} {{>contact/element.html}} {{/socials}}