This commit is contained in:
parent
cea27a6af9
commit
fe0ccd913c
12 changed files with 70 additions and 112 deletions
|
@ -95,10 +95,13 @@ onion = "http://youraddress.onion/"
|
|||
This file is stored at `/app/config/config.toml`
|
||||
|
||||
```toml
|
||||
scheme = "https" # http or https (fallback to 'http' if none)
|
||||
domain = "sub.domain.tld" # your domain (fallback to 'localhost' if none)
|
||||
port = 8080 # port used (fallback to '8080' if none)
|
||||
mail = "your.mail at host.com"
|
||||
lang = "lang"
|
||||
onion = "http://youraddress.onion/"
|
||||
app_name = "Nickname"
|
||||
app_name = "Nickname" # fallback to 'EWP' if none
|
||||
name = "Firstname"
|
||||
fullname = "Fullname"
|
||||
```
|
||||
|
|
|
@ -11,13 +11,15 @@ use crate::template::Template;
|
|||
pub struct FileConfig {
|
||||
/// http/https
|
||||
pub scheme: Option<String>,
|
||||
/// Domain name "sub.domain.tld"
|
||||
pub domain: Option<String>,
|
||||
/// Port used
|
||||
pub port: Option<u16>,
|
||||
/// Mail of owner
|
||||
pub mail: Option<String>,
|
||||
/// Lang used
|
||||
pub lang: Option<String>,
|
||||
/// Adress .onion for Tor
|
||||
/// .onion address for Tor of the app
|
||||
pub onion: Option<String>,
|
||||
/// App name
|
||||
pub app_name: Option<String>,
|
||||
|
@ -32,6 +34,7 @@ impl FileConfig {
|
|||
fn new() -> Self {
|
||||
Self {
|
||||
scheme: Some("http".into()),
|
||||
domain: Some("localhost".into()),
|
||||
port: Some(8080),
|
||||
app_name: Some("EWP".into()),
|
||||
..FileConfig::default()
|
||||
|
@ -57,6 +60,7 @@ impl FileConfig {
|
|||
port: test(a.port, d.port),
|
||||
mail: test(a.mail, d.mail),
|
||||
lang: test(a.lang, d.lang),
|
||||
domain: test(a.domain, d.domain),
|
||||
onion: test(a.onion, d.onion),
|
||||
app_name: test(a.app_name, d.app_name),
|
||||
name: test(a.name, d.name),
|
||||
|
@ -110,6 +114,7 @@ pub fn get_config(file_path: &str) -> Config {
|
|||
tmpl: Template {
|
||||
directory: format!("{}/{}", files_root, templates_dir),
|
||||
app_name: internal_config.app_name.unwrap(),
|
||||
url: internal_config.domain.unwrap(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::cell::Ref;
|
||||
|
||||
use actix_web::dev::ConnectionInfo;
|
||||
use cached::proc_macro::cached;
|
||||
use reqwest::Client;
|
||||
|
||||
use crate::config::FileConfig;
|
||||
|
||||
#[cached]
|
||||
pub fn get_reqwest_client() -> Client {
|
||||
Client::builder()
|
||||
|
@ -13,6 +12,12 @@ pub fn get_reqwest_client() -> Client {
|
|||
}
|
||||
|
||||
/// Get URL of the app
|
||||
pub fn get_url(info: Ref<'_, ConnectionInfo>) -> String {
|
||||
format!("{}://{}", info.scheme(), info.host())
|
||||
pub fn get_url(fc: FileConfig) -> String {
|
||||
/* let port = match fc.scheme.as_deref() {
|
||||
Some("https") if fc.port == Some(443) => String::new(),
|
||||
Some("http") if fc.port == Some(80) => String::new(),
|
||||
_ => format!(":{}", fc.port.unwrap()),
|
||||
}; */
|
||||
|
||||
format!("{}://{}", fc.scheme.unwrap(), fc.domain.unwrap())
|
||||
}
|
||||
|
|
|
@ -1,33 +1,30 @@
|
|||
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
||||
use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, routes, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
||||
#[routes]
|
||||
#[get("/.well-known/security.txt")]
|
||||
#[get("/security.txt")]
|
||||
async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_securitytxt(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn security(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_securitytxt(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
struct SecurityTemplate {
|
||||
url: String,
|
||||
contact: String,
|
||||
pref_lang: String,
|
||||
url: String,
|
||||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_securitytxt(config: Config, url: String) -> String {
|
||||
fn build_securitytxt(config: Config) -> String {
|
||||
config.tmpl.render(
|
||||
"security.txt",
|
||||
SecurityTemplate {
|
||||
url: format!("{}/.well-known/security.txt", get_url(config.fc.clone())),
|
||||
contact: config.fc.mail.unwrap_or_default(),
|
||||
pref_lang: config.fc.lang.unwrap_or_default(),
|
||||
url: format!("{}/.well-known/security.txt", url),
|
||||
},
|
||||
Infos::default(),
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ use ::rss::{
|
|||
extension::atom::{AtomExtension, Link},
|
||||
Category, Channel, Guid, Image, Item,
|
||||
};
|
||||
use actix_web::{dev::ConnectionInfo, get, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
|
||||
use chrono_tz::Europe;
|
||||
|
@ -29,11 +29,8 @@ use crate::{
|
|||
const MIME_TYPE_RSS: &str = "application/rss+xml";
|
||||
|
||||
#[get("/blog")]
|
||||
async fn index(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_index(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn index(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_index(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
|
@ -44,7 +41,7 @@ struct BlogIndexTemplate {
|
|||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_index(config: Config, url: String) -> String {
|
||||
fn build_index(config: Config) -> String {
|
||||
let mut posts = get_posts("data/blog");
|
||||
|
||||
// Sort from newest to oldest
|
||||
|
@ -68,7 +65,6 @@ fn build_index(config: Config, url: String) -> String {
|
|||
config.fc.name.unwrap_or_default()
|
||||
)),
|
||||
page_kw: Some(["blog", "blogging"].join(", ")),
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -188,21 +184,13 @@ struct BlogPostTemplate {
|
|||
}
|
||||
|
||||
#[get("/blog/p/{id}")]
|
||||
async fn page(
|
||||
req: HttpRequest,
|
||||
path: web::Path<(String,)>,
|
||||
config: web::Data<Config>,
|
||||
) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_post(
|
||||
path.into_inner().0,
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_post(path.into_inner().0, config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
fn build_post(file: String, config: Config, url: String) -> String {
|
||||
fn build_post(file: String, config: Config) -> String {
|
||||
let mut post = None;
|
||||
let (infos, toc) = get_post(&mut post, file, config.fc.name.unwrap_or_default(), url);
|
||||
let (infos, toc) = get_post(&mut post, file, config.fc.name.unwrap_or_default());
|
||||
|
||||
config.tmpl.render(
|
||||
"blog/post.html",
|
||||
|
@ -218,12 +206,7 @@ fn build_post(file: String, config: Config, url: String) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
fn get_post(
|
||||
post: &mut Option<File>,
|
||||
filename: String,
|
||||
name: String,
|
||||
url: String,
|
||||
) -> (Infos, String) {
|
||||
fn get_post(post: &mut Option<File>, filename: String, name: String) -> (Infos, String) {
|
||||
let blog_dir = "data/blog";
|
||||
let ext = ".md";
|
||||
|
||||
|
@ -264,24 +247,20 @@ fn get_post(
|
|||
.collect::<Vec<String>>()
|
||||
.join(", "),
|
||||
),
|
||||
url,
|
||||
},
|
||||
toc,
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/blog/rss")]
|
||||
async fn rss(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
async fn rss(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
.append_header(("content-type", MIME_TYPE_RSS))
|
||||
.body(build_rss(
|
||||
config.get_ref().to_owned(),
|
||||
req.connection_info().to_owned(),
|
||||
))
|
||||
.body(build_rss(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[once(time = 10800)] // 3h
|
||||
fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
||||
fn build_rss(config: Config) -> String {
|
||||
let mut posts = get_posts("data/blog");
|
||||
|
||||
// Sort from newest to oldest
|
||||
|
@ -294,7 +273,7 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
|||
posts.drain(max..);
|
||||
}
|
||||
|
||||
let link_to_site = format!("{}://{}", info.scheme(), info.host());
|
||||
let link_to_site = get_url(config.fc.clone());
|
||||
let author = if let (Some(mail), Some(name)) = (config.fc.mail, config.fc.fullname.to_owned()) {
|
||||
Some(format!("{mail} ({name})"))
|
||||
} else {
|
||||
|
|
|
@ -6,10 +6,7 @@ use std::fs::read_to_string;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
misc::{
|
||||
markdown::{read_file, File, TypeFileMetadata},
|
||||
utils::get_url,
|
||||
},
|
||||
misc::markdown::{read_file, File, TypeFileMetadata},
|
||||
template::{Infos, NavBar},
|
||||
};
|
||||
|
||||
|
@ -26,11 +23,8 @@ pub fn pages(cfg: &mut web::ServiceConfig) {
|
|||
}
|
||||
|
||||
#[get("")]
|
||||
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -125,7 +119,7 @@ fn remove_paragraphs(list: &mut [File]) {
|
|||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_page(config: Config, url: String) -> String {
|
||||
fn build_page(config: Config) -> String {
|
||||
let contacts_dir = "data/contacts";
|
||||
let ext = ".md";
|
||||
|
||||
|
@ -172,7 +166,6 @@ fn build_page(config: Config, url: String) -> String {
|
|||
page_title: Some("Contacts".into()),
|
||||
page_desc: Some(format!("Réseaux d'{}", config.fc.name.unwrap_or_default())),
|
||||
page_kw: None,
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,20 +2,16 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
misc::{
|
||||
github::{fetch_pr, ProjectState},
|
||||
utils::get_url,
|
||||
},
|
||||
misc::github::{fetch_pr, ProjectState},
|
||||
template::{Infos, NavBar},
|
||||
};
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
||||
#[get("/contrib")]
|
||||
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
let url = get_url(req.connection_info());
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned(), url).await)
|
||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()).await)
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
|
@ -46,7 +42,7 @@ struct Pull {
|
|||
}
|
||||
|
||||
#[once(time = 600)] // 10min
|
||||
async fn build_page(config: Config, url: String) -> String {
|
||||
async fn build_page(config: Config) -> String {
|
||||
let navbar = NavBar {
|
||||
contrib: true,
|
||||
..NavBar::default()
|
||||
|
@ -158,7 +154,6 @@ async fn build_page(config: Config, url: String) -> String {
|
|||
config.fc.name.unwrap_or_default()
|
||||
)),
|
||||
page_kw: None,
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
misc::utils::get_url,
|
||||
template::{Infos, NavBar},
|
||||
};
|
||||
|
||||
#[get("/")]
|
||||
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
|
@ -23,7 +19,7 @@ struct IndexTemplate {
|
|||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_page(config: Config, url: String) -> String {
|
||||
fn build_page(config: Config) -> String {
|
||||
config.tmpl.render(
|
||||
"index.html",
|
||||
IndexTemplate {
|
||||
|
@ -41,7 +37,6 @@ fn build_page(config: Config, url: String) -> String {
|
|||
page_title: config.fc.fullname,
|
||||
page_desc: Some("Page principale".into()),
|
||||
page_kw: None,
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
||||
|
@ -8,11 +8,8 @@ use crate::{
|
|||
template::{Infos, NavBar},
|
||||
};
|
||||
|
||||
pub async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::NotFound().body(build_page(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::NotFound().body(build_page(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
|
@ -23,12 +20,12 @@ struct NotFoundTemplate {
|
|||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_page(config: Config, url: String) -> String {
|
||||
fn build_page(config: Config) -> String {
|
||||
config.tmpl.render(
|
||||
"404.html",
|
||||
NotFoundTemplate {
|
||||
navbar: NavBar::default(),
|
||||
www: url,
|
||||
www: get_url(config.fc.clone()),
|
||||
onion: config.fc.onion,
|
||||
},
|
||||
Infos {
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use glob::glob;
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
misc::{
|
||||
markdown::{read_file, File, TypeFileMetadata},
|
||||
utils::get_url,
|
||||
},
|
||||
misc::markdown::{read_file, File, TypeFileMetadata},
|
||||
template::{Infos, NavBar},
|
||||
};
|
||||
|
||||
#[get("/portfolio")]
|
||||
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[derive(Content, Debug)]
|
||||
|
@ -31,7 +25,7 @@ struct PortfolioTemplate<'a> {
|
|||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
fn build_page(config: Config, url: String) -> String {
|
||||
fn build_page(config: Config) -> String {
|
||||
let projects_dir = "data/projects";
|
||||
let ext = ".md";
|
||||
|
||||
|
@ -79,7 +73,6 @@ fn build_page(config: Config, url: String) -> String {
|
|||
config.fc.name.unwrap_or_default()
|
||||
)),
|
||||
page_kw: None,
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
|
||||
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
||||
use crate::{config::Config, template::Infos};
|
||||
|
||||
#[get("/web3")]
|
||||
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(
|
||||
config.get_ref().to_owned(),
|
||||
get_url(req.connection_info()),
|
||||
))
|
||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
||||
}
|
||||
|
||||
#[once]
|
||||
fn build_page(config: Config, url: String) -> String {
|
||||
fn build_page(config: Config) -> String {
|
||||
config.tmpl.render(
|
||||
"web3.html",
|
||||
(),
|
||||
|
@ -20,7 +17,6 @@ fn build_page(config: Config, url: String) -> String {
|
|||
page_title: Some("Mylloon".into()),
|
||||
page_desc: Some("Coin reculé de l'internet".into()),
|
||||
page_kw: None,
|
||||
url,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ pub struct Template {
|
|||
pub directory: String,
|
||||
/// App name
|
||||
pub app_name: String,
|
||||
/// URL of app
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
/// Structure used by /routes/*.rs
|
||||
|
@ -18,8 +20,6 @@ pub struct Infos {
|
|||
pub page_desc: Option<String>,
|
||||
/// Keywords
|
||||
pub page_kw: Option<String>,
|
||||
/// URL of the website
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Content, Debug, Default)]
|
||||
|
@ -64,7 +64,7 @@ impl Template {
|
|||
page_title: info.page_title,
|
||||
page_desc: info.page_desc.map(add_quotes),
|
||||
page_kw: info.page_kw.map(add_quotes),
|
||||
url: add_quotes(info.url),
|
||||
url: add_quotes(self.url.to_owned()),
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue