From d2b520d9b6628ba4214f49714394bd57069def9a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 14 Apr 2023 12:25:14 +0200 Subject: [PATCH] cut the md reader in half --- src/routes/portfolio.rs | 8 ++++---- src/template.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/routes/portfolio.rs b/src/routes/portfolio.rs index afd07f1..a01cfdb 100644 --- a/src/routes/portfolio.rs +++ b/src/routes/portfolio.rs @@ -5,7 +5,7 @@ use ramhorns::Content; use crate::{ config::Config, - template::{read_md, File, Infos}, + template::{read_md_file, File, Infos}, }; #[get("/portfolio")] @@ -28,13 +28,13 @@ pub fn get_page(config: Config) -> String { // Get bots apps let mut bots_apps = Vec::new(); for entry in glob(&format!("{projects_dir}/bots/*{ext}")).unwrap() { - bots_apps.push(read_md(&entry.unwrap().to_string_lossy())); + bots_apps.push(read_md_file(&entry.unwrap().to_string_lossy())); } // Get perso apps let mut perso_apps = Vec::new(); for entry in glob(&format!("{projects_dir}/perso/*{ext}")).unwrap() { - perso_apps.push(read_md(&entry.unwrap().to_string_lossy())); + perso_apps.push(read_md_file(&entry.unwrap().to_string_lossy())); } config.tmpl.render( @@ -42,7 +42,7 @@ pub fn get_page(config: Config) -> String { PortfolioTemplate { bots_app: bots_apps, persos_app: perso_apps, - univ_content: read_md(&format!("{projects_dir}/univ{ext}")).content, + univ_content: read_md_file(&format!("{projects_dir}/univ{ext}")).content, }, Infos { page_title: Some("Portfolio".to_string()), diff --git a/src/template.rs b/src/template.rs index 847f41f..edc0fd0 100644 --- a/src/template.rs +++ b/src/template.rs @@ -71,12 +71,16 @@ pub struct File { pub content: String, } -pub fn read_md(filename: &str) -> File { +pub fn read_md_file(filename: &str) -> File { // Read markdown file - let mut text = fs::read_to_string(filename).unwrap(); + let text = fs::read_to_string(filename).unwrap(); + read_md(&text) +} + +pub fn read_md(raw_text: &str) -> File { // Transform LaTeX to MathML - text = latex2mathml::replace(&text).unwrap(); + let text = latex2mathml::replace(raw_text).unwrap(); let parse_option = markdown::ParseOptions { constructs: markdown::Constructs {