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;
|
pub mod github;
|
||||||
mod utils;
|
pub mod utils;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use cached::proc_macro::cached;
|
use cached::proc_macro::cached;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
|
use crate::template::{read_md_file, File, Infos};
|
||||||
|
|
||||||
#[cached]
|
#[cached]
|
||||||
pub fn get_reqwest_client() -> Client {
|
pub fn get_reqwest_client() -> Client {
|
||||||
Client::builder()
|
Client::builder()
|
||||||
|
@ -8,3 +10,24 @@ pub fn get_reqwest_client() -> Client {
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.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 cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
||||||
use crate::{
|
use crate::{config::Config, misc::utils::get_post, template::File};
|
||||||
config::Config,
|
|
||||||
template::{read_md_file, File, Infos},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[get("/blog")]
|
#[get("/blog")]
|
||||||
pub async fn index(config: web::Data<Config>) -> impl Responder {
|
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 {
|
pub fn get_page(file: String, config: Config) -> String {
|
||||||
let blog_dir = "data/blog";
|
let mut post = None;
|
||||||
let ext = ".md";
|
let infos = get_post(&mut post, file);
|
||||||
|
|
||||||
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()),
|
|
||||||
};
|
|
||||||
|
|
||||||
config
|
config
|
||||||
.tmpl
|
.tmpl
|
||||||
|
|
Loading…
Reference in a new issue