This commit is contained in:
parent
00f65be0f3
commit
7339486467
3 changed files with 27 additions and 14 deletions
|
@ -1,2 +1,2 @@
|
|||
pub mod github;
|
||||
mod utils;
|
||||
pub mod utils;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use cached::proc_macro::cached;
|
||||
use reqwest::Client;
|
||||
|
||||
use crate::template::{read_md_file, File, Infos};
|
||||
|
||||
#[cached]
|
||||
pub fn get_reqwest_client() -> Client {
|
||||
Client::builder()
|
||||
|
@ -8,3 +10,24 @@ pub fn get_reqwest_client() -> Client {
|
|||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_post(post: &mut Option<File>, file: String) -> Infos {
|
||||
let blog_dir = "data/blog";
|
||||
let ext = ".md";
|
||||
|
||||
*post = read_md_file(&format!("{blog_dir}/{file}{ext}"));
|
||||
|
||||
let title = match post {
|
||||
Some(data) => match &data.metadata.info.title {
|
||||
Some(text) => text,
|
||||
None => &file,
|
||||
},
|
||||
None => &file,
|
||||
};
|
||||
|
||||
Infos {
|
||||
page_title: Some(format!("Post: {}", title)),
|
||||
page_desc: Some("Blog d'Anri".to_string()),
|
||||
page_kw: Some(["blog", "blogging", "write", "writing"].join(", ")),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ use actix_web::{get, web, HttpResponse, Responder};
|
|||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
template::{read_md_file, File, Infos},
|
||||
};
|
||||
use crate::{config::Config, misc::utils::get_post, template::File};
|
||||
|
||||
#[get("/blog")]
|
||||
pub async fn index(config: web::Data<Config>) -> impl Responder {
|
||||
|
@ -28,15 +25,8 @@ pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl
|
|||
}
|
||||
|
||||
pub fn get_page(file: String, config: Config) -> String {
|
||||
let blog_dir = "data/blog";
|
||||
let ext = ".md";
|
||||
|
||||
let post = read_md_file(&format!("{blog_dir}/{file}{ext}"));
|
||||
|
||||
let infos = Infos {
|
||||
page_title: Some(format!("Post: {file}")),
|
||||
page_desc: Some("Blog d'Anri".to_string()),
|
||||
};
|
||||
let mut post = None;
|
||||
let infos = get_post(&mut post, file);
|
||||
|
||||
config
|
||||
.tmpl
|
||||
|
|
Loading…
Reference in a new issue