This commit is contained in:
Maciej Jur 2024-09-16 23:01:38 +02:00
parent f97ec9e036
commit 1c9d234430
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
9 changed files with 480 additions and 455 deletions

View file

@ -1,8 +1,8 @@
use camino::Utf8Path;
use hauchiwa::{Link, LinkDate, Sack};
use hauchiwa::Sack;
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
use crate::{html::Post, text::md::parse};
use crate::{html::Post, text::md::parse, Link, LinkDate};
const INTRO: &str = r#"
##

View file

@ -1,7 +1,7 @@
use hauchiwa::{LinkDate, Sack};
use hauchiwa::Sack;
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
use crate::html::page;
use crate::{html::page, LinkDate};
pub fn list<'s, 'g, 'html>(
sack: &'s Sack,

View file

@ -1,6 +1,10 @@
use hauchiwa::{Outline, Sack, TreePage};
use std::collections::HashMap;
use camino::Utf8Path;
use hauchiwa::{Outline, Sack};
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use crate::{html::Wiki, Link};
/// Render the outline for a document
pub(crate) fn show_outline(outline: Outline) -> impl Renderable {
@ -41,9 +45,50 @@ pub(crate) fn emit_bibliography(bib: Vec<String>) -> impl Renderable {
)
}
#[derive(Debug)]
pub struct TreePage {
pub link: Option<Link>,
pub subs: HashMap<String, TreePage>,
}
impl TreePage {
fn new() -> Self {
TreePage {
link: None,
subs: HashMap::new(),
}
}
fn add_link(&mut self, link: &Link) {
let mut ptr = self;
for part in link.path.iter().skip(1) {
ptr = ptr.subs.entry(part.to_string()).or_insert(TreePage::new());
}
ptr.link = Some(link.clone());
}
fn from_iter(iter: impl Iterator<Item = Link>) -> Self {
let mut tree = Self::new();
for link in iter {
tree.add_link(&link);
}
tree
}
}
/// Render the page tree
pub(crate) fn show_page_tree(sack: &Sack, glob: &str) -> impl Renderable {
let tree = sack.get_tree(glob);
let tree =
TreePage::from_iter(
sack.get_meta::<Wiki>(glob)
.into_iter()
.map(|(path, meta)| Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: None,
}),
);
maud_move!(
h2 .link-tree__heading {

View file

@ -9,19 +9,19 @@ pub mod wiki;
use std::collections::HashMap;
use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Datelike, Utc};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hayagriva::Library;
use camino::Utf8Path;
use chrono::Datelike;
use hauchiwa::{Bibliography, Outline, Sack};
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
pub(crate) use home::home;
use post::article;
pub(crate) use post::Post;
use serde::Deserialize;
pub(crate) use slideshow::Slideshow;
pub(crate) use wiki::Wiki;
use crate::LinkDate;
fn navbar() -> impl Renderable {
static ITEMS: &[(&str, &str)] = &[
("Posts", "/posts/"),
@ -198,7 +198,7 @@ where
)
}
pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String {
pub(crate) fn search(sack: &Sack) -> String {
page(
sack,
maud!(
@ -222,7 +222,7 @@ pub fn as_html(
flox(&meta.title, parsed, sack, outline, bibliography)
}
pub(crate) fn flox<'p, 's, 'html>(
pub(crate) fn flox(
title: &str,
parsed: &str,
sack: &Sack,

View file

@ -1,6 +1,6 @@
use camino::{Utf8Path, Utf8PathBuf};
use camino::Utf8Path;
use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
@ -37,17 +37,6 @@ pub fn as_html(
.into()
}
pub fn as_link(meta: &Post, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Date(LinkDate {
link: Link {
path,
name: meta.title.to_owned(),
desc: meta.desc.to_owned(),
},
date: meta.date.to_owned(),
}))
}
pub fn post<'s, 'p, 'html>(
meta: &'p Post,
parsed: &'p str,

View file

@ -1,6 +1,6 @@
use camino::{Utf8Path, Utf8PathBuf};
use camino::Utf8Path;
use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
use hauchiwa::{Bibliography, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
@ -33,7 +33,7 @@ pub fn parse_content(
.map(|chunk| {
chunk
.split("\n---\n")
.map(|slide| crate::text::md::parse(&slide, sack, path, library).0)
.map(|slide| crate::text::md::parse(slide, sack, path, library).0)
.collect::<Vec<_>>()
})
.map(|stack| match stack.len() > 1 {
@ -60,17 +60,6 @@ pub fn as_html(
show(slides, sack, parsed)
}
pub fn as_link(slides: &Slideshow, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Date(LinkDate {
link: Link {
path,
name: slides.title.to_owned(),
desc: slides.desc.to_owned(),
},
date: slides.date.to_owned(),
}))
}
pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
crate::html::bare(
sack,

View file

@ -1,5 +1,5 @@
use camino::{Utf8Path, Utf8PathBuf};
use hauchiwa::{Bibliography, Link, Linkable, Outline, Sack};
use camino::Utf8Path;
use hauchiwa::{Bibliography, Outline, Sack};
use hayagriva::Library;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use serde::Deserialize;
@ -29,14 +29,6 @@ pub fn as_html(
wiki(meta, parsed, sack, outline, bibliography)
}
pub fn as_link(meta: &Wiki, path: Utf8PathBuf) -> Option<Linkable> {
Some(Linkable::Link(Link {
path,
name: meta.title.to_owned(),
desc: None,
}))
}
fn wiki(
matter: &Wiki,
parsed: &str,

View file

@ -2,9 +2,10 @@ mod html;
mod text;
mod ts;
use camino::Utf8Path;
use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Utc};
use clap::{Parser, ValueEnum};
use hauchiwa::{Collection, Link, LinkDate, Processor, Website};
use hauchiwa::{Collection, Processor, Website};
use html::{Post, Slideshow, Wiki};
use hypertext::Renderable;
@ -20,6 +21,25 @@ enum Mode {
Watch,
}
#[derive(Debug, Clone)]
pub struct Link {
pub path: Utf8PathBuf,
pub name: String,
pub desc: Option<String>,
}
#[derive(Debug, Clone)]
pub struct LinkDate {
pub link: Link,
pub date: DateTime<Utc>,
}
#[derive(Debug, Clone)]
pub enum Linkable {
Link(Link),
Date(LinkDate),
}
fn main() {
let args = Args::parse();
@ -32,7 +52,6 @@ fn main() {
Processor {
read_content: crate::html::post::parse_content,
to_html: crate::html::post::as_html,
to_link: crate::html::post::as_link,
},
),
Collection::glob_with::<Post>(
@ -42,7 +61,6 @@ fn main() {
Processor {
read_content: crate::html::post::parse_content,
to_html: crate::html::post::as_html,
to_link: crate::html::post::as_link,
},
),
Collection::glob_with::<Slideshow>(
@ -52,7 +70,6 @@ fn main() {
Processor {
read_content: crate::html::slideshow::parse_content,
to_html: crate::html::slideshow::as_html,
to_link: crate::html::slideshow::as_link,
},
),
Collection::glob_with::<Wiki>(
@ -62,7 +79,6 @@ fn main() {
Processor {
read_content: crate::html::wiki::parse_content,
to_html: crate::html::wiki::as_html,
to_link: crate::html::wiki::as_link,
},
),
Collection::glob_with::<Post>(
@ -72,7 +88,6 @@ fn main() {
Processor {
read_content: crate::html::post::parse_content,
to_html: crate::html::as_html,
to_link: crate::html::post::as_link,
},
),
])
@ -85,7 +100,7 @@ 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(crate::html::search, "search/index.html".into())
.add_virtual(
|sack| {
crate::html::to_list(

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use camino::{Utf8Path, Utf8PathBuf};
use camino::Utf8Path;
use hauchiwa::{Bibliography, Outline, Sack};
use hayagriva::{
archive::ArchivedStyle,
@ -86,23 +86,18 @@ pub fn parse(
(parsed, outline, Bibliography(bib))
}
fn make_bib<'a, 'b>(
stream: Vec<Event<'a>>,
lib: &'b Library,
) -> (Vec<Event<'a>>, Option<Vec<String>>) {
fn make_bib<'a>(stream: Vec<Event<'a>>, lib: &Library) -> (Vec<Event<'a>>, Option<Vec<String>>) {
let mut driver = BibliographyDriver::new();
for event in stream.iter() {
match event {
Event::InlineMath(ref text) => match lib.get(text) {
Some(entry) => driver.citation(CitationRequest::from_items(
if let Event::InlineMath(ref text) = event {
if let Some(entry) = lib.get(text) {
driver.citation(CitationRequest::from_items(
vec![CitationItem::with_entry(entry)],
&STYLE,
&LOCALE,
)),
None => (),
},
_ => (),
))
}
}
}