add raw post endpoint
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending approval
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending approval
This commit is contained in:
parent
95b92699ed
commit
d68071f48c
2 changed files with 20 additions and 0 deletions
|
@ -51,6 +51,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)
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue