This commit is contained in:
Maciej Jur 2024-09-16 00:15:24 +02:00
parent b0b0d9d5df
commit f97ec9e036
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
2 changed files with 62 additions and 12 deletions

View file

@ -1,9 +1,8 @@
use std::collections::HashMap; use camino::Utf8Path;
use hauchiwa::{Link, LinkDate, Sack};
use hauchiwa::Sack;
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable}; use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
use crate::text::md::parse; use crate::{html::Post, text::md::parse};
const INTRO: &str = r#" const INTRO: &str = r#"
## ##
@ -43,9 +42,20 @@ fn photo() -> impl Renderable {
fn latest(sack: &Sack) -> impl Renderable { fn latest(sack: &Sack) -> impl Renderable {
let links = { let links = {
let mut links = sack.get_links("**"); let mut list = sack
links.sort_by(|a, b| b.date.cmp(&a.date)); .get_meta::<Post>("**")
links .into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect::<Vec<_>>();
list.sort_by(|a, b| b.date.cmp(&a.date));
list
}; };
maud_move!( maud_move!(
@ -81,5 +91,8 @@ pub(crate) fn home(sack: &Sack, main: &str) -> String {
} }
); );
crate::html::page(sack, main, "Home".into(), None).unwrap().render().into() crate::html::page(sack, main, "Home".into(), None)
.unwrap()
.render()
.into()
} }

View file

@ -2,8 +2,9 @@ mod html;
mod text; mod text;
mod ts; mod ts;
use camino::Utf8Path;
use clap::{Parser, ValueEnum}; use clap::{Parser, ValueEnum};
use hauchiwa::{Collection, Processor, Website}; use hauchiwa::{Collection, Link, LinkDate, Processor, Website};
use html::{Post, Slideshow, Wiki}; use html::{Post, Slideshow, Wiki};
use hypertext::Renderable; use hypertext::Renderable;
@ -89,21 +90,57 @@ fn main() {
|sack| { |sack| {
crate::html::to_list( crate::html::to_list(
sack, sack,
sack.get_links("projects/**/*.html"), sack.get_meta::<Post>("projects/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Projects".into(), "Projects".into(),
) )
}, },
"projects/index.html".into(), "projects/index.html".into(),
) )
.add_virtual( .add_virtual(
|sack| crate::html::to_list(sack, sack.get_links("posts/**/*.html"), "Posts".into()), |sack| {
crate::html::to_list(
sack,
sack.get_meta::<Post>("posts/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Posts".into(),
)
},
"posts/index.html".into(), "posts/index.html".into(),
) )
.add_virtual( .add_virtual(
|sack| { |sack| {
crate::html::to_list( crate::html::to_list(
sack, sack,
sack.get_links("slides/**/*.html"), sack.get_meta::<Slideshow>("slides/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Slideshows".into(), "Slideshows".into(),
) )
}, },