refactor
This commit is contained in:
parent
f97ec9e036
commit
1c9d234430
|
@ -1,8 +1,8 @@
|
||||||
use camino::Utf8Path;
|
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::{html::Post, text::md::parse};
|
use crate::{html::Post, text::md::parse, Link, LinkDate};
|
||||||
|
|
||||||
const INTRO: &str = r#"
|
const INTRO: &str = r#"
|
||||||
## かもし
|
## かもし
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use hauchiwa::{LinkDate, Sack};
|
use hauchiwa::Sack;
|
||||||
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
|
||||||
|
|
||||||
use crate::html::page;
|
use crate::{html::page, LinkDate};
|
||||||
|
|
||||||
pub fn list<'s, 'g, 'html>(
|
pub fn list<'s, 'g, 'html>(
|
||||||
sack: &'s Sack,
|
sack: &'s Sack,
|
||||||
|
|
|
@ -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 hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
|
|
||||||
|
use crate::{html::Wiki, Link};
|
||||||
|
|
||||||
/// Render the outline for a document
|
/// Render the outline for a document
|
||||||
pub(crate) fn show_outline(outline: Outline) -> impl Renderable {
|
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
|
/// Render the page tree
|
||||||
pub(crate) fn show_page_tree(sack: &Sack, glob: &str) -> impl Renderable {
|
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!(
|
maud_move!(
|
||||||
h2 .link-tree__heading {
|
h2 .link-tree__heading {
|
||||||
|
|
|
@ -9,19 +9,19 @@ pub mod wiki;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::Utf8Path;
|
||||||
use chrono::{DateTime, Datelike, Utc};
|
use chrono::Datelike;
|
||||||
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
|
use hauchiwa::{Bibliography, Outline, Sack};
|
||||||
use hayagriva::Library;
|
|
||||||
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
|
|
||||||
pub(crate) use home::home;
|
pub(crate) use home::home;
|
||||||
use post::article;
|
use post::article;
|
||||||
pub(crate) use post::Post;
|
pub(crate) use post::Post;
|
||||||
use serde::Deserialize;
|
|
||||||
pub(crate) use slideshow::Slideshow;
|
pub(crate) use slideshow::Slideshow;
|
||||||
pub(crate) use wiki::Wiki;
|
pub(crate) use wiki::Wiki;
|
||||||
|
|
||||||
|
use crate::LinkDate;
|
||||||
|
|
||||||
fn navbar() -> impl Renderable {
|
fn navbar() -> impl Renderable {
|
||||||
static ITEMS: &[(&str, &str)] = &[
|
static ITEMS: &[(&str, &str)] = &[
|
||||||
("Posts", "/posts/"),
|
("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(
|
page(
|
||||||
sack,
|
sack,
|
||||||
maud!(
|
maud!(
|
||||||
|
@ -222,7 +222,7 @@ pub fn as_html(
|
||||||
flox(&meta.title, parsed, sack, outline, bibliography)
|
flox(&meta.title, parsed, sack, outline, bibliography)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn flox<'p, 's, 'html>(
|
pub(crate) fn flox(
|
||||||
title: &str,
|
title: &str,
|
||||||
parsed: &str,
|
parsed: &str,
|
||||||
sack: &Sack,
|
sack: &Sack,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::Utf8Path;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
|
use hauchiwa::{Bibliography, Outline, Sack};
|
||||||
use hayagriva::Library;
|
use hayagriva::Library;
|
||||||
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -37,17 +37,6 @@ pub fn as_html(
|
||||||
.into()
|
.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>(
|
pub fn post<'s, 'p, 'html>(
|
||||||
meta: &'p Post,
|
meta: &'p Post,
|
||||||
parsed: &'p str,
|
parsed: &'p str,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::Utf8Path;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
|
use hauchiwa::{Bibliography, Outline, Sack};
|
||||||
use hayagriva::Library;
|
use hayagriva::Library;
|
||||||
use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -33,7 +33,7 @@ pub fn parse_content(
|
||||||
.map(|chunk| {
|
.map(|chunk| {
|
||||||
chunk
|
chunk
|
||||||
.split("\n---\n")
|
.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<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.map(|stack| match stack.len() > 1 {
|
.map(|stack| match stack.len() > 1 {
|
||||||
|
@ -60,17 +60,6 @@ pub fn as_html(
|
||||||
show(slides, sack, parsed)
|
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 {
|
pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
|
||||||
crate::html::bare(
|
crate::html::bare(
|
||||||
sack,
|
sack,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::Utf8Path;
|
||||||
use hauchiwa::{Bibliography, Link, Linkable, Outline, Sack};
|
use hauchiwa::{Bibliography, Outline, Sack};
|
||||||
use hayagriva::Library;
|
use hayagriva::Library;
|
||||||
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -29,14 +29,6 @@ pub fn as_html(
|
||||||
wiki(meta, parsed, sack, outline, bibliography)
|
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(
|
fn wiki(
|
||||||
matter: &Wiki,
|
matter: &Wiki,
|
||||||
parsed: &str,
|
parsed: &str,
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -2,9 +2,10 @@ mod html;
|
||||||
mod text;
|
mod text;
|
||||||
mod ts;
|
mod ts;
|
||||||
|
|
||||||
use camino::Utf8Path;
|
use camino::{Utf8Path, Utf8PathBuf};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use hauchiwa::{Collection, Link, LinkDate, Processor, Website};
|
use hauchiwa::{Collection, Processor, Website};
|
||||||
use html::{Post, Slideshow, Wiki};
|
use html::{Post, Slideshow, Wiki};
|
||||||
use hypertext::Renderable;
|
use hypertext::Renderable;
|
||||||
|
|
||||||
|
@ -20,6 +21,25 @@ enum Mode {
|
||||||
Watch,
|
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() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
|
@ -32,7 +52,6 @@ fn main() {
|
||||||
Processor {
|
Processor {
|
||||||
read_content: crate::html::post::parse_content,
|
read_content: crate::html::post::parse_content,
|
||||||
to_html: crate::html::post::as_html,
|
to_html: crate::html::post::as_html,
|
||||||
to_link: crate::html::post::as_link,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Collection::glob_with::<Post>(
|
Collection::glob_with::<Post>(
|
||||||
|
@ -42,7 +61,6 @@ fn main() {
|
||||||
Processor {
|
Processor {
|
||||||
read_content: crate::html::post::parse_content,
|
read_content: crate::html::post::parse_content,
|
||||||
to_html: crate::html::post::as_html,
|
to_html: crate::html::post::as_html,
|
||||||
to_link: crate::html::post::as_link,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Collection::glob_with::<Slideshow>(
|
Collection::glob_with::<Slideshow>(
|
||||||
|
@ -52,7 +70,6 @@ fn main() {
|
||||||
Processor {
|
Processor {
|
||||||
read_content: crate::html::slideshow::parse_content,
|
read_content: crate::html::slideshow::parse_content,
|
||||||
to_html: crate::html::slideshow::as_html,
|
to_html: crate::html::slideshow::as_html,
|
||||||
to_link: crate::html::slideshow::as_link,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Collection::glob_with::<Wiki>(
|
Collection::glob_with::<Wiki>(
|
||||||
|
@ -62,7 +79,6 @@ fn main() {
|
||||||
Processor {
|
Processor {
|
||||||
read_content: crate::html::wiki::parse_content,
|
read_content: crate::html::wiki::parse_content,
|
||||||
to_html: crate::html::wiki::as_html,
|
to_html: crate::html::wiki::as_html,
|
||||||
to_link: crate::html::wiki::as_link,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Collection::glob_with::<Post>(
|
Collection::glob_with::<Post>(
|
||||||
|
@ -72,7 +88,6 @@ fn main() {
|
||||||
Processor {
|
Processor {
|
||||||
read_content: crate::html::post::parse_content,
|
read_content: crate::html::post::parse_content,
|
||||||
to_html: crate::html::as_html,
|
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(),
|
|sack| crate::html::map(sack).unwrap().render().to_owned().into(),
|
||||||
"map/index.html".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(
|
.add_virtual(
|
||||||
|sack| {
|
|sack| {
|
||||||
crate::html::to_list(
|
crate::html::to_list(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::Utf8Path;
|
||||||
use hauchiwa::{Bibliography, Outline, Sack};
|
use hauchiwa::{Bibliography, Outline, Sack};
|
||||||
use hayagriva::{
|
use hayagriva::{
|
||||||
archive::ArchivedStyle,
|
archive::ArchivedStyle,
|
||||||
|
@ -86,23 +86,18 @@ pub fn parse(
|
||||||
(parsed, outline, Bibliography(bib))
|
(parsed, outline, Bibliography(bib))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_bib<'a, 'b>(
|
fn make_bib<'a>(stream: Vec<Event<'a>>, lib: &Library) -> (Vec<Event<'a>>, Option<Vec<String>>) {
|
||||||
stream: Vec<Event<'a>>,
|
|
||||||
lib: &'b Library,
|
|
||||||
) -> (Vec<Event<'a>>, Option<Vec<String>>) {
|
|
||||||
let mut driver = BibliographyDriver::new();
|
let mut driver = BibliographyDriver::new();
|
||||||
|
|
||||||
for event in stream.iter() {
|
for event in stream.iter() {
|
||||||
match event {
|
if let Event::InlineMath(ref text) = event {
|
||||||
Event::InlineMath(ref text) => match lib.get(text) {
|
if let Some(entry) = lib.get(text) {
|
||||||
Some(entry) => driver.citation(CitationRequest::from_items(
|
driver.citation(CitationRequest::from_items(
|
||||||
vec![CitationItem::with_entry(entry)],
|
vec![CitationItem::with_entry(entry)],
|
||||||
&STYLE,
|
&STYLE,
|
||||||
&LOCALE,
|
&LOCALE,
|
||||||
)),
|
))
|
||||||
None => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue