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