add raw post endpoint
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 2m43s

This commit is contained in:
Mylloon 2024-07-23 16:53:15 +02:00 committed by Mylloon
parent 87d0fa3c11
commit 71e9776aa2
2 changed files with 20 additions and 0 deletions

View file

@ -58,6 +58,7 @@ async fn main() -> Result<()> {
.service(blog::index) .service(blog::index)
.service(blog::rss) .service(blog::rss)
.service(blog::page) .service(blog::page)
.service(blog::rawpage)
.service(contrib::page) .service(contrib::page)
.service(cours::page) .service(cours::page)
.service(cv::page) .service(cv::page)

View file

@ -1,5 +1,6 @@
use std::{ use std::{
collections::hash_map::DefaultHasher, collections::hash_map::DefaultHasher,
fs,
hash::{Hash, Hasher}, hash::{Hash, Hasher},
}; };
@ -197,6 +198,24 @@ pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl
)) ))
} }
#[get("/blog/raw/{id}")]
pub async fn rawpage(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
let filename = format!(
"{}/{BLOG_DIR}/{POST_DIR}/{}.md",
config.locations.data_dir,
path.into_inner().0
);
match fs::read_to_string(filename) {
Ok(text) => HttpResponse::Ok()
.content_type(ContentType::plaintext())
.body(text),
Err(_) => HttpResponse::NotFound()
.content_type(ContentType::plaintext())
.body("post not found"),
}
}
fn build_post(file: &str, config: Config) -> String { fn build_post(file: &str, config: Config) -> String {
let mut post = None; let mut post = None;
let (infos, toc) = get_post( let (infos, toc) = get_post(