This commit is contained in:
parent
568a864dc9
commit
80e27bd32c
8 changed files with 37 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::config::Config;
|
||||
use crate::{config::Config, template::Infos};
|
||||
use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
|
||||
use ramhorns::Content;
|
||||
|
||||
|
@ -31,6 +31,7 @@ fn get_security(config: Config, info: ConnectionInfo) -> String {
|
|||
info.host()
|
||||
),
|
||||
},
|
||||
Infos::default(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::config::Config;
|
||||
use crate::{config::Config, template::Infos};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use ramhorns::Content;
|
||||
|
||||
|
@ -11,5 +11,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
struct PortfolioTemplate {}
|
||||
|
||||
pub fn get_page(config: Config) -> std::string::String {
|
||||
config.tmpl.render("contrib.html", PortfolioTemplate {})
|
||||
config
|
||||
.tmpl
|
||||
.render("contrib.html", PortfolioTemplate {}, Infos::default())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::{config::Config, template::Infos};
|
||||
|
||||
#[get("/")]
|
||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
|
@ -12,5 +12,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
struct IndexTemplate {}
|
||||
|
||||
pub fn get_page(config: Config) -> std::string::String {
|
||||
config.tmpl.render("index.html", IndexTemplate {})
|
||||
config
|
||||
.tmpl
|
||||
.render("index.html", IndexTemplate {}, Infos::default())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::{config::Config, template::Infos};
|
||||
|
||||
#[get("/networks")]
|
||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
|
@ -12,5 +12,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
struct NetworksTemplate {}
|
||||
|
||||
pub fn get_page(config: Config) -> std::string::String {
|
||||
config.tmpl.render("networks.html", NetworksTemplate {})
|
||||
config
|
||||
.tmpl
|
||||
.render("networks.html", NetworksTemplate {}, Infos::default())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_web::{web, HttpResponse, Responder};
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::{config::Config, template::Infos};
|
||||
|
||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::NotFound().body(get_page(config.get_ref().clone()))
|
||||
|
@ -11,5 +11,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
struct Error404Template {}
|
||||
|
||||
pub fn get_page(config: Config) -> std::string::String {
|
||||
config.tmpl.render("404.html", Error404Template {})
|
||||
config
|
||||
.tmpl
|
||||
.render("404.html", Error404Template {}, Infos::default())
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use ramhorns::Content;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
template::{read_md, File},
|
||||
template::{read_md, File, Infos},
|
||||
};
|
||||
|
||||
#[get("/portfolio")]
|
||||
|
@ -14,7 +14,6 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
|
||||
#[derive(Content)]
|
||||
struct PortfolioTemplate {
|
||||
page_title: String,
|
||||
bots_app: Vec<File>,
|
||||
persos_app: Vec<File>,
|
||||
univ_content: String,
|
||||
|
@ -39,10 +38,13 @@ pub fn get_page(config: Config) -> std::string::String {
|
|||
config.tmpl.render(
|
||||
"portfolio.html",
|
||||
PortfolioTemplate {
|
||||
page_title: "Portfolio".to_string(),
|
||||
bots_app: bots_apps,
|
||||
persos_app: perso_apps,
|
||||
univ_content: read_md(&format!("{projects_dir}/univ{ext}")).content,
|
||||
},
|
||||
Infos {
|
||||
page_title: Some("Portfolio".to_string()),
|
||||
page_desc: None,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -7,19 +7,29 @@ pub struct Template {
|
|||
pub app_name: String,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Infos {
|
||||
pub page_title: Option<String>,
|
||||
pub page_desc: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Content)]
|
||||
struct Data<T> {
|
||||
app_name: String,
|
||||
page_title: Option<String>,
|
||||
page_desc: Option<String>,
|
||||
data: T,
|
||||
}
|
||||
|
||||
impl Template {
|
||||
pub fn render<C: Content>(&self, template: &str, data: C) -> String {
|
||||
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.clone(),
|
||||
page_title: info.page_title,
|
||||
page_desc: info.page_desc,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<head dir="rtl">
|
||||
<title>{{#data}}{{page_title}}{{/data}} - {{app_name}}</title>
|
||||
<title>{{page_title}}{{#page_title}} - {{/page_title}}{{app_name}}</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
@ -30,8 +30,8 @@
|
|||
<meta name="msapplication-TileColor" content="#ffffff" />
|
||||
<meta name="msapplication-config" content="icons/browserconfig.xml" />
|
||||
<meta name="theme-color" content="#2a2424" />
|
||||
<meta content="{{ title }}" property="og:title" />
|
||||
<meta content="{{ desc }}" property="og:description" />
|
||||
<meta content="{{page_title}}" property="og:title" />
|
||||
<meta content="{{page_desc}}" property="og:description" />
|
||||
<meta content="icons/apple-touch-icon.png" property="og:image" />
|
||||
<meta content="#43B581" data-react-helmet="true" name="theme-color" />
|
||||
</head>
|
||||
|
|
Loading…
Reference in a new issue