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

View file

@ -8,9 +8,8 @@
<header>{{>navbar.html}}</header>
<main>
<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>
<ul>
{{#socials}} {{>contact/element.html}} {{/socials}}