Compare commits
No commits in common. "4ae660983f955c801f17fcc32f4ee19267d7cfb5" and "adfb769df6d6b34d58d6bc59605a7e805e1206cb" have entirely different histories.
4ae660983f
...
adfb769df6
9 changed files with 52 additions and 38 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1095,7 +1095,6 @@ dependencies = [
|
|||
"serde_yml",
|
||||
"toml",
|
||||
"urlencoding",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -32,7 +32,6 @@ mime_guess = "2.0"
|
|||
urlencoding = "2.1"
|
||||
regex = "1.10"
|
||||
cyborgtime = "2.1.1"
|
||||
walkdir = "2.5"
|
||||
|
||||
[lints.clippy]
|
||||
pedantic = "warn"
|
||||
|
|
|
@ -13,8 +13,8 @@ use crate::routes::{
|
|||
mod config;
|
||||
mod template;
|
||||
|
||||
mod routes;
|
||||
mod utils;
|
||||
mod routes;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> Result<()> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{config::Config, template::InfosPage, utils::misc::get_url};
|
||||
use crate::{config::Config, utils::misc::get_url, template::InfosPage};
|
||||
use actix_web::{get, http::header::ContentType, routes, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
|
|
@ -67,7 +67,7 @@ struct BlogPostTemplate {
|
|||
toc: String,
|
||||
}
|
||||
|
||||
#[get("/blog/p/{id:.*}")]
|
||||
#[get("/blog/p/{id}")]
|
||||
pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
|
||||
Html(build_post(
|
||||
&path.into_inner().0,
|
||||
|
|
|
@ -4,8 +4,8 @@ use ramhorns::Content;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
template::{InfosPage, NavBar},
|
||||
utils::misc::{get_url, Html},
|
||||
template::{InfosPage, NavBar},
|
||||
};
|
||||
|
||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||
|
|
|
@ -36,12 +36,21 @@ fn build_page(config: Config) -> String {
|
|||
let ext = ".md";
|
||||
|
||||
// Get about
|
||||
let about = read_file(format!("{projects_dir}/about.md"), MType::Generic);
|
||||
let about = read_file(
|
||||
format!("{projects_dir}/about.md"),
|
||||
MType::Generic,
|
||||
);
|
||||
|
||||
// Get apps
|
||||
let apps = glob(&format!("{apps_dir}/*{ext}"))
|
||||
.unwrap()
|
||||
.map(|e| read_file(e.unwrap().to_string_lossy().to_string(), MType::Portfolio).unwrap())
|
||||
.map(|e| {
|
||||
read_file(
|
||||
e.unwrap().to_string_lossy().to_string(),
|
||||
MType::Portfolio,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.collect::<Vec<File>>();
|
||||
|
||||
let appdata = if apps.is_empty() {
|
||||
|
@ -53,7 +62,13 @@ fn build_page(config: Config) -> String {
|
|||
// Get archived apps
|
||||
let archived_apps = glob(&format!("{apps_dir}/archive/*{ext}"))
|
||||
.unwrap()
|
||||
.map(|e| read_file(e.unwrap().to_string_lossy().to_string(), MType::Portfolio).unwrap())
|
||||
.map(|e| {
|
||||
read_file(
|
||||
e.unwrap().to_string_lossy().to_string(),
|
||||
MType::Portfolio,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.collect::<Vec<File>>();
|
||||
|
||||
let archived_appdata = if archived_apps.is_empty() {
|
||||
|
|
|
@ -3,8 +3,8 @@ use cached::proc_macro::once;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
template::InfosPage,
|
||||
utils::misc::{make_kw, Html},
|
||||
template::InfosPage,
|
||||
};
|
||||
|
||||
#[get("/web3")]
|
||||
|
|
|
@ -12,7 +12,6 @@ use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
|
|||
use chrono_tz::Europe;
|
||||
use comrak::{parse_document, Arena};
|
||||
use ramhorns::Content;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
|
@ -60,44 +59,46 @@ impl Hash for Post {
|
|||
}
|
||||
|
||||
pub fn get_posts(location: &str) -> Vec<Post> {
|
||||
WalkDir::new(location)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|entry| {
|
||||
entry.file_type().is_file() && entry.path().extension().is_some_and(|s| s == "md")
|
||||
})
|
||||
std::fs::read_dir(location)
|
||||
.map_or_else(
|
||||
|_| vec![],
|
||||
|res| {
|
||||
res.flatten()
|
||||
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md"))
|
||||
.collect::<Vec<std::fs::DirEntry>>()
|
||||
},
|
||||
)
|
||||
.iter()
|
||||
.filter_map(|f| {
|
||||
let fname = f.file_name();
|
||||
let filename = fname.to_string_lossy();
|
||||
let file_without_ext = filename.split_at(filename.len() - 3).0;
|
||||
|
||||
let file_metadata = std::fs::read_to_string(f.path()).map_or_else(
|
||||
|_| FileMetadataBlog {
|
||||
title: Some(file_without_ext.into()),
|
||||
..FileMetadataBlog::default()
|
||||
},
|
||||
|text| {
|
||||
let arena = Arena::new();
|
||||
let file_metadata = std::fs::read_to_string(format!("{location}/{filename}"))
|
||||
.map_or_else(
|
||||
|_| FileMetadataBlog {
|
||||
title: Some(file_without_ext.into()),
|
||||
..FileMetadataBlog::default()
|
||||
},
|
||||
|text| {
|
||||
let arena = Arena::new();
|
||||
|
||||
let options = get_options();
|
||||
let root = parse_document(&arena, &text, &options);
|
||||
let mut metadata = get(root, MType::Blog).blog.unwrap();
|
||||
let options = get_options();
|
||||
let root = parse_document(&arena, &text, &options);
|
||||
let mut metadata = get(root, MType::Blog).blog.unwrap();
|
||||
|
||||
// Always have a title
|
||||
metadata.title = metadata
|
||||
.title
|
||||
.map_or_else(|| Some(file_without_ext.into()), Some);
|
||||
// Always have a title
|
||||
metadata.title = metadata
|
||||
.title
|
||||
.map_or_else(|| Some(file_without_ext.into()), Some);
|
||||
|
||||
metadata
|
||||
},
|
||||
);
|
||||
metadata
|
||||
},
|
||||
);
|
||||
|
||||
if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) {
|
||||
let url =
|
||||
f.path().to_string_lossy().strip_prefix(location).unwrap()[1..].to_owned();
|
||||
|
||||
Some(Post {
|
||||
url: url[..url.len() - 3].to_owned(),
|
||||
url: file_without_ext.into(),
|
||||
title: file_metadata.title.unwrap(),
|
||||
date: file_metadata.date.unwrap_or({
|
||||
let m = f.metadata().unwrap();
|
||||
|
|
Loading…
Reference in a new issue