move get_post to utils
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-19 20:08:15 +02:00
parent 00f65be0f3
commit 7339486467
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 27 additions and 14 deletions

View file

@ -1,2 +1,2 @@
pub mod github;
mod utils;
pub mod utils;

View file

@ -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(", ")),
}
}

View file

@ -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