mylloon.fr/src/template.rs
Mylloon 9dfcc1101d
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
Basic cours support (#44)
feat: Basic support for new `/cours` endpoint (not ready for release yet), see commit description for more

- Basic /cours support
- Fix LaTeX support (see #47 / cours+blog)
  - Better detection of when there is LaTeX in document
  - Don't shuffle markdown and LaTeX processing (thanks to comrak)
  - Macros on release
- Local image support (cours+blog)
- PDF support
- Support of markdown files integration in other markdown files
- Very basic exclusion support in toc (need a lot of improvement!!)
- Update multiple dependencies (actix-web, ramhorns, comrak, reqwest, hljs)
- Reformat some code
- ToC in /cours support (very basic, works via building it in rust and processing it in js)
- Remove very old assets (font + jspdf)
- Hide navbar when printing the website
- New tag in index page
- Fix OCaml support for HLJS + add "pseudocode" derived from Julia

Reviewed-on: #44
Co-authored-by: Mylloon <kennel.anri@tutanota.com>
Co-committed-by: Mylloon <kennel.anri@tutanota.com>
2024-04-01 18:11:46 +02:00

72 lines
1.8 KiB
Rust

use ramhorns::{Content, Ramhorns};
/// Structure used in the config variable of the app
#[derive(Clone, Debug)]
pub struct Template {
/// Root directory where templates are stored
pub directory: String,
/// App name
pub app_name: String,
/// URL of app
pub url: String,
/// Name of user
pub name: Option<String>,
}
/// Structure used by /routes/*.rs
#[derive(Debug, Default)]
pub struct Infos {
/// Title
pub page_title: Option<String>,
/// Description
pub page_desc: Option<String>,
/// Keywords
pub page_kw: Option<String>,
}
/// Information on what page the user is currently
#[derive(Content, Debug, Default)]
pub struct NavBar {
pub index: bool,
pub blog: bool,
pub portfolio: bool,
pub contact: bool,
pub contrib: bool,
pub cours: bool,
}
/// Final structure given to template
#[derive(Content, Debug)]
struct Data<T> {
/// App name
app_name: String,
/// App URL
url: String,
/// Title of the page
page_title: Option<String>,
/// Description of the page
page_desc: Option<String>,
/// Keywords of the the page
page_kw: Option<String>,
/// Author's name
page_author: Option<String>,
/// Data needed to render the page
data: T,
}
impl Template {
pub fn render<C: Content>(&self, template: &str, data: C, info: Infos) -> String {
let mut templates: Ramhorns = Ramhorns::lazy(&self.directory).unwrap();
let tplt = templates.from_file(template).unwrap();
tplt.render(&Data {
app_name: self.app_name.to_owned(),
url: self.url.to_owned(),
page_title: info.page_title,
page_desc: info.page_desc,
page_kw: info.page_kw,
page_author: self.name.clone(),
data,
})
}
}