This commit is contained in:
Maciej Jur 2024-09-15 01:44:37 +02:00
parent 474d30c24d
commit a0df7388d8
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
8 changed files with 270 additions and 241 deletions

2
rustfmt.toml Normal file
View file

@ -0,0 +1,2 @@
tab_spaces = 4
hard_tabs = true

View file

@ -1,18 +1,17 @@
mod head;
mod home;
mod isodate;
mod list;
mod misc;
mod post;
mod slideshow;
mod special;
mod wiki;
mod head;
pub mod post;
pub mod slideshow;
pub mod wiki;
use std::collections::HashMap;
use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Datelike, Utc};
use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
@ -133,7 +132,6 @@ where
))
}
fn full<'s, 'p, 'html>(
sack: &'s Sack,
main: impl Renderable + 'p,
@ -143,10 +141,7 @@ where
's: 'html,
'p: 'html,
{
let main = maud_move!(
(navbar())
(main)
);
let main = maud_move!((navbar())(main));
bare(sack, main, title, None)
}
@ -161,11 +156,7 @@ where
's: 'html,
'p: 'html,
{
let main = maud_move!(
(navbar())
(main)
(footer(sack))
);
let main = maud_move!((navbar())(main)(footer(sack)));
bare(sack, main, title, js)
}
@ -214,14 +205,13 @@ pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String {
main #app {}
),
String::from("Search"),
Some(&["search".into()])
Some(&["search".into()]),
)
.unwrap()
.render()
.into()
}
/// Represents a simple post.
#[derive(Deserialize, Debug, Clone)]
pub(crate) struct Flox {
@ -231,8 +221,7 @@ pub(crate) struct Flox {
pub(crate) desc: Option<String>,
}
impl Content for Flox {
fn parse_content(
pub fn parse_content(
content: &str,
sack: &Sack,
path: &Utf8Path,
@ -241,27 +230,26 @@ impl Content for Flox {
crate::text::md::parse(content, sack, path, library)
}
fn as_html(
&self,
pub fn as_html(
meta: &Flox,
parsed: &str,
sack: &Sack,
outline: Outline,
bibliography: Bibliography,
) -> String {
flox(&self.title, parsed, sack, outline, bibliography)
flox(&meta.title, parsed, sack, outline, bibliography)
}
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
pub fn as_link(meta: &Flox, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Date(LinkDate {
link: Link {
path,
name: self.title.to_owned(),
desc: self.desc.to_owned(),
name: meta.title.to_owned(),
desc: meta.desc.to_owned(),
},
date: self.date.to_owned(),
date: meta.date.to_owned(),
}))
}
}
pub(crate) fn flox<'p, 's, 'html>(
title: &str,
@ -293,7 +281,7 @@ pub(crate) fn flox<'p, 's, 'html>(
}
),
String::from("Flox"),
Some(&["editor".into()])
Some(&["editor".into()]),
)
.unwrap()
.render()

View file

@ -1,22 +1,21 @@
use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
/// Represents a simple post.
#[derive(Deserialize, Debug, Clone)]
pub(crate) struct Post {
pub(crate) title: String,
pub struct Post {
pub title: String,
#[serde(with = "super::isodate")]
pub(crate) date: DateTime<Utc>,
pub(crate) desc: Option<String>,
pub(crate) scripts: Option<Vec<String>>,
pub date: DateTime<Utc>,
pub desc: Option<String>,
pub scripts: Option<Vec<String>>,
}
impl Content for Post {
fn parse_content(
pub fn parse_content(
content: &str,
sack: &Sack,
path: &Utf8Path,
@ -25,30 +24,29 @@ impl Content for Post {
crate::text::md::parse(content, sack, path, library)
}
fn as_html(
&self,
pub fn as_html(
meta: &Post,
parsed: &str,
sack: &Sack,
outline: Outline,
bibliography: Bibliography,
) -> String {
post(self, parsed, sack, outline, bibliography)
post(meta, parsed, sack, outline, bibliography)
.unwrap()
.render()
.into()
}
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
pub fn as_link(meta: &Post, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Date(LinkDate {
link: Link {
path,
name: self.title.to_owned(),
desc: self.desc.to_owned(),
name: meta.title.to_owned(),
desc: meta.desc.to_owned(),
},
date: self.date.to_owned(),
date: meta.date.to_owned(),
}))
}
}
pub fn post<'s, 'p, 'html>(
meta: &'p Post,

View file

@ -1,6 +1,6 @@
use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
@ -22,8 +22,7 @@ pub(crate) struct Slideshow {
pub desc: Option<String>,
}
impl Content for Slideshow {
fn parse_content(
pub fn parse_content(
content: &str,
sack: &Sack,
path: &Utf8Path,
@ -51,21 +50,26 @@ impl Content for Slideshow {
(parsed, Outline(vec![]), Bibliography(None))
}
fn as_html(&self, parsed: &str, sack: &Sack, _: Outline, _: Bibliography) -> String {
show(self, sack, parsed)
pub fn as_html(
slides: &Slideshow,
parsed: &str,
sack: &Sack,
_: Outline,
_: Bibliography,
) -> String {
show(slides, sack, parsed)
}
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
pub fn as_link(slides: &Slideshow, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Date(LinkDate {
link: Link {
path,
name: self.title.to_owned(),
desc: self.desc.to_owned(),
name: slides.title.to_owned(),
desc: slides.desc.to_owned(),
},
date: self.date.to_owned(),
date: slides.date.to_owned(),
}))
}
}
pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
crate::html::bare(
@ -80,7 +84,7 @@ pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
style { (Raw(CSS)) }
),
fm.title.clone(),
Some(&["reveal".into()])
Some(&["reveal".into()]),
)
.unwrap()
.render()

View file

View file

@ -1,5 +1,5 @@
use camino::{Utf8Path, Utf8PathBuf};
use hauchiwa::{Bibliography, Content, Link, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Link, Linkable, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
@ -10,8 +10,7 @@ pub struct Wiki {
pub title: String,
}
impl Content for Wiki {
fn parse_content(
pub fn parse_content(
content: &str,
sack: &Sack,
path: &Utf8Path,
@ -20,24 +19,23 @@ impl Content for Wiki {
crate::text::md::parse(content, sack, path, library)
}
fn as_html(
&self,
pub fn as_html(
meta: &Wiki,
parsed: &str,
sack: &Sack,
outline: Outline,
bibliography: Bibliography,
) -> String {
wiki(self, parsed, sack, outline, bibliography)
wiki(meta, parsed, sack, outline, bibliography)
}
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
pub fn as_link(meta: &Wiki, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Link(Link {
path,
name: self.title.to_owned(),
name: meta.title.to_owned(),
desc: None,
}))
}
}
fn wiki(
matter: &Wiki,

View file

@ -3,7 +3,7 @@ mod text;
mod ts;
use clap::{Parser, ValueEnum};
use hauchiwa::Website;
use hauchiwa::{Loader, Processor, Website};
use html::{Flox, Post, Slideshow, Wiki};
use hypertext::Renderable;
@ -22,12 +22,48 @@ enum Mode {
fn main() {
let args = Args::parse();
let processor_post = Processor {
read_content: crate::html::post::parse_content,
to_html: crate::html::post::as_html,
to_link: crate::html::post::as_link,
};
let processor_slideshow = Processor {
read_content: crate::html::slideshow::parse_content,
to_html: crate::html::slideshow::as_html,
to_link: crate::html::slideshow::as_link,
};
let processor_wiki = Processor {
read_content: crate::html::wiki::parse_content,
to_html: crate::html::wiki::as_html,
to_link: crate::html::wiki::as_link,
};
let processor_flox = Processor {
read_content: crate::html::parse_content,
to_html: crate::html::as_html,
to_link: crate::html::as_link,
};
let website = Website::design()
.content::<Post>("content/about.md", ["md"].into())
.content::<Post>("content/posts/**/*", ["md", "mdx"].into())
.content::<Slideshow>("content/slides/**/*", ["md", "lhs"].into())
.content::<Wiki>("content/wiki/**/*", ["md"].into())
.content::<Flox>("content/projects/flox.md", ["md"].into())
.add_loaders(vec![
Loader::glob_with::<Post>("content", "about.md", ["md"].into(), processor_post.clone()),
Loader::glob_with::<Post>(
"content",
"posts/**/*",
["md", "mdx"].into(),
processor_post.clone(),
),
Loader::glob_with::<Slideshow>(
"content",
"slides/**/*",
["md", "lhs"].into(),
processor_slideshow,
),
Loader::glob_with::<Wiki>("content", "wiki/**/*", ["md"].into(), processor_wiki),
Loader::glob_with::<Flox>("content", "projects/flox.md", ["md"].into(), processor_flox),
])
.js("search", "./js/search/dist/search.js")
.js("photos", "./js/vanilla/photos.js")
.js("reveal", "./js/vanilla/reveal.js")
@ -37,12 +73,15 @@ fn main() {
|sack| crate::html::map(sack).unwrap().render().to_owned().into(),
"map/index.html".into(),
)
.add_virtual(|sack| crate::html::search(sack), "search/index.html".into())
.add_virtual(
|sack| crate::html::search(sack),
"search/index.html".into(),
|sack| {
crate::html::to_list(
sack,
sack.get_links("projects/**/*.html"),
"Projects".into(),
)
.add_virtual(
|sack| crate::html::to_list(sack, sack.get_links("projects/**/*.html"), "Projects".into()),
},
"projects/index.html".into(),
)
.add_virtual(