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",
|
"serde_yml",
|
||||||
"toml",
|
"toml",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
"walkdir",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -32,7 +32,6 @@ mime_guess = "2.0"
|
||||||
urlencoding = "2.1"
|
urlencoding = "2.1"
|
||||||
regex = "1.10"
|
regex = "1.10"
|
||||||
cyborgtime = "2.1.1"
|
cyborgtime = "2.1.1"
|
||||||
walkdir = "2.5"
|
|
||||||
|
|
||||||
[lints.clippy]
|
[lints.clippy]
|
||||||
pedantic = "warn"
|
pedantic = "warn"
|
||||||
|
|
|
@ -13,8 +13,8 @@ use crate::routes::{
|
||||||
mod config;
|
mod config;
|
||||||
mod template;
|
mod template;
|
||||||
|
|
||||||
mod routes;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
mod routes;
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> Result<()> {
|
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 actix_web::{get, http::header::ContentType, routes, web, HttpResponse, Responder};
|
||||||
use cached::proc_macro::once;
|
use cached::proc_macro::once;
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
|
|
|
@ -67,7 +67,7 @@ struct BlogPostTemplate {
|
||||||
toc: String,
|
toc: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/blog/p/{id:.*}")]
|
#[get("/blog/p/{id}")]
|
||||||
pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
|
pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
|
||||||
Html(build_post(
|
Html(build_post(
|
||||||
&path.into_inner().0,
|
&path.into_inner().0,
|
||||||
|
|
|
@ -4,8 +4,8 @@ use ramhorns::Content;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
template::{InfosPage, NavBar},
|
|
||||||
utils::misc::{get_url, Html},
|
utils::misc::{get_url, Html},
|
||||||
|
template::{InfosPage, NavBar},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
|
|
|
@ -36,12 +36,21 @@ fn build_page(config: Config) -> String {
|
||||||
let ext = ".md";
|
let ext = ".md";
|
||||||
|
|
||||||
// Get about
|
// 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
|
// Get apps
|
||||||
let apps = glob(&format!("{apps_dir}/*{ext}"))
|
let apps = glob(&format!("{apps_dir}/*{ext}"))
|
||||||
.unwrap()
|
.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>>();
|
.collect::<Vec<File>>();
|
||||||
|
|
||||||
let appdata = if apps.is_empty() {
|
let appdata = if apps.is_empty() {
|
||||||
|
@ -53,7 +62,13 @@ fn build_page(config: Config) -> String {
|
||||||
// Get archived apps
|
// Get archived apps
|
||||||
let archived_apps = glob(&format!("{apps_dir}/archive/*{ext}"))
|
let archived_apps = glob(&format!("{apps_dir}/archive/*{ext}"))
|
||||||
.unwrap()
|
.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>>();
|
.collect::<Vec<File>>();
|
||||||
|
|
||||||
let archived_appdata = if archived_apps.is_empty() {
|
let archived_appdata = if archived_apps.is_empty() {
|
||||||
|
|
|
@ -3,8 +3,8 @@ use cached::proc_macro::once;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
template::InfosPage,
|
|
||||||
utils::misc::{make_kw, Html},
|
utils::misc::{make_kw, Html},
|
||||||
|
template::InfosPage,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[get("/web3")]
|
#[get("/web3")]
|
||||||
|
|
|
@ -12,7 +12,6 @@ use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
|
||||||
use chrono_tz::Europe;
|
use chrono_tz::Europe;
|
||||||
use comrak::{parse_document, Arena};
|
use comrak::{parse_document, Arena};
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
use walkdir::WalkDir;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
|
@ -60,18 +59,23 @@ impl Hash for Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_posts(location: &str) -> Vec<Post> {
|
pub fn get_posts(location: &str) -> Vec<Post> {
|
||||||
WalkDir::new(location)
|
std::fs::read_dir(location)
|
||||||
.into_iter()
|
.map_or_else(
|
||||||
.filter_map(Result::ok)
|
|_| vec![],
|
||||||
.filter(|entry| {
|
|res| {
|
||||||
entry.file_type().is_file() && entry.path().extension().is_some_and(|s| s == "md")
|
res.flatten()
|
||||||
})
|
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md"))
|
||||||
|
.collect::<Vec<std::fs::DirEntry>>()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.iter()
|
||||||
.filter_map(|f| {
|
.filter_map(|f| {
|
||||||
let fname = f.file_name();
|
let fname = f.file_name();
|
||||||
let filename = fname.to_string_lossy();
|
let filename = fname.to_string_lossy();
|
||||||
let file_without_ext = filename.split_at(filename.len() - 3).0;
|
let file_without_ext = filename.split_at(filename.len() - 3).0;
|
||||||
|
|
||||||
let file_metadata = std::fs::read_to_string(f.path()).map_or_else(
|
let file_metadata = std::fs::read_to_string(format!("{location}/{filename}"))
|
||||||
|
.map_or_else(
|
||||||
|_| FileMetadataBlog {
|
|_| FileMetadataBlog {
|
||||||
title: Some(file_without_ext.into()),
|
title: Some(file_without_ext.into()),
|
||||||
..FileMetadataBlog::default()
|
..FileMetadataBlog::default()
|
||||||
|
@ -93,11 +97,8 @@ pub fn get_posts(location: &str) -> Vec<Post> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) {
|
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 {
|
Some(Post {
|
||||||
url: url[..url.len() - 3].to_owned(),
|
url: file_without_ext.into(),
|
||||||
title: file_metadata.title.unwrap(),
|
title: file_metadata.title.unwrap(),
|
||||||
date: file_metadata.date.unwrap_or({
|
date: file_metadata.date.unwrap_or({
|
||||||
let m = f.metadata().unwrap();
|
let m = f.metadata().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue