add content type, allowing firefox to see source code of pages
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
This commit is contained in:
parent
6fe2ec2df3
commit
49af05a565
9 changed files with 55 additions and 26 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
use actix_web::{
|
||||||
|
http::header::{self, ContentType, TryIntoHeaderValue},
|
||||||
|
HttpRequest, HttpResponse, Responder,
|
||||||
|
};
|
||||||
use cached::proc_macro::cached;
|
use cached::proc_macro::cached;
|
||||||
use reqwest::Client;
|
use reqwest::{Client, StatusCode};
|
||||||
|
|
||||||
use crate::config::FileConfig;
|
use crate::config::FileConfig;
|
||||||
|
|
||||||
|
@ -26,3 +30,18 @@ pub fn get_url(fc: FileConfig) -> String {
|
||||||
pub fn make_kw(list: &[&str]) -> Option<String> {
|
pub fn make_kw(list: &[&str]) -> Option<String> {
|
||||||
Some(list.join(", "))
|
Some(list.join(", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send HTML file
|
||||||
|
pub struct Html(pub String);
|
||||||
|
impl Responder for Html {
|
||||||
|
type Body = String;
|
||||||
|
|
||||||
|
fn respond_to(self, _req: &HttpRequest) -> HttpResponse<Self::Body> {
|
||||||
|
let mut res = HttpResponse::with_body(StatusCode::OK, self.0);
|
||||||
|
res.headers_mut().insert(
|
||||||
|
header::CONTENT_TYPE,
|
||||||
|
ContentType::html().try_into_value().unwrap(),
|
||||||
|
);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
||||||
use actix_web::{get, routes, web, HttpResponse, Responder};
|
use actix_web::{get, http::header::ContentType, routes, web, HttpResponse, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ use ramhorns::Content;
|
||||||
#[get("/.well-known/security.txt")]
|
#[get("/.well-known/security.txt")]
|
||||||
#[get("/security.txt")]
|
#[get("/security.txt")]
|
||||||
async fn security(config: web::Data<Config>) -> impl Responder {
|
async fn security(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_securitytxt(config.get_ref().to_owned()))
|
HttpResponse::Ok()
|
||||||
|
.content_type(ContentType::plaintext())
|
||||||
|
.body(build_securitytxt(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
@ -32,7 +34,9 @@ fn build_securitytxt(config: Config) -> String {
|
||||||
|
|
||||||
#[get("/humans.txt")]
|
#[get("/humans.txt")]
|
||||||
async fn humans(config: web::Data<Config>) -> impl Responder {
|
async fn humans(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_humanstxt(config.get_ref().to_owned()))
|
HttpResponse::Ok()
|
||||||
|
.content_type(ContentType::plaintext())
|
||||||
|
.body(build_humanstxt(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
@ -57,7 +61,9 @@ fn build_humanstxt(config: Config) -> String {
|
||||||
|
|
||||||
#[get("/robots.txt")]
|
#[get("/robots.txt")]
|
||||||
async fn robots() -> impl Responder {
|
async fn robots() -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_robotstxt())
|
HttpResponse::Ok()
|
||||||
|
.content_type(ContentType::plaintext())
|
||||||
|
.body(build_robotstxt())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[once]
|
#[once]
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
markdown::{
|
markdown::{
|
||||||
get_metadata, get_options, read_file, File, FileMetadataBlog, TypeFileMetadata,
|
get_metadata, get_options, read_file, File, FileMetadataBlog, TypeFileMetadata,
|
||||||
},
|
},
|
||||||
utils::{get_url, make_kw},
|
utils::{get_url, make_kw, Html},
|
||||||
},
|
},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ const MIME_TYPE_RSS: &str = "application/rss+xml";
|
||||||
|
|
||||||
#[get("/blog")]
|
#[get("/blog")]
|
||||||
async fn index(config: web::Data<Config>) -> impl Responder {
|
async fn index(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_index(config.get_ref().to_owned()))
|
Html(build_index(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
@ -185,7 +185,7 @@ struct BlogPostTemplate {
|
||||||
|
|
||||||
#[get("/blog/p/{id}")]
|
#[get("/blog/p/{id}")]
|
||||||
async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
|
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()))
|
Html(build_post(path.into_inner().0, config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_post(file: String, config: Config) -> String {
|
fn build_post(file: String, config: Config) -> String {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder};
|
use actix_web::{get, routes, web, HttpRequest, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
misc::{
|
misc::{
|
||||||
markdown::{read_file, File, TypeFileMetadata},
|
markdown::{read_file, File, TypeFileMetadata},
|
||||||
utils::make_kw,
|
utils::{make_kw, Html},
|
||||||
},
|
},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
|
@ -27,7 +27,7 @@ pub fn pages(cfg: &mut web::ServiceConfig) {
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
Html(build_page(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -4,17 +4,17 @@ use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
misc::{
|
misc::{
|
||||||
github::{fetch_pr, ProjectState},
|
github::{fetch_pr, ProjectState},
|
||||||
utils::make_kw,
|
utils::{make_kw, Html},
|
||||||
},
|
},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{get, web, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
||||||
#[get("/contrib")]
|
#[get("/contrib")]
|
||||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()).await)
|
Html(build_page(config.get_ref().to_owned()).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{get, web, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
misc::utils::make_kw,
|
misc::utils::{make_kw, Html},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
Html(build_page(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
misc::utils::get_url,
|
misc::utils::{get_url, Html},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::NotFound().body(build_page(config.get_ref().to_owned()))
|
Html(build_page(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{get, web, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
@ -7,14 +7,14 @@ use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
misc::{
|
misc::{
|
||||||
markdown::{read_file, File, TypeFileMetadata},
|
markdown::{read_file, File, TypeFileMetadata},
|
||||||
utils::make_kw,
|
utils::{make_kw, Html},
|
||||||
},
|
},
|
||||||
template::{Infos, NavBar},
|
template::{Infos, NavBar},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[get("/portfolio")]
|
#[get("/portfolio")]
|
||||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
Html(build_page(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{get, web, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
|
|
||||||
use crate::{config::Config, misc::utils::make_kw, template::Infos};
|
use crate::{
|
||||||
|
config::Config,
|
||||||
|
misc::utils::{make_kw, Html},
|
||||||
|
template::Infos,
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/web3")]
|
#[get("/web3")]
|
||||||
async fn page(config: web::Data<Config>) -> impl Responder {
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
HttpResponse::Ok().body(build_page(config.get_ref().to_owned()))
|
Html(build_page(config.get_ref().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[once]
|
#[once]
|
||||||
|
|
Loading…
Reference in a new issue