This commit is contained in:
Maciej Jur 2024-09-17 21:43:32 +02:00
parent 730b9aa4f8
commit dafc42a615
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
11 changed files with 107 additions and 68 deletions

8
Cargo.lock generated
View file

@ -659,9 +659,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]] [[package]]
name = "grass" name = "grass"
version = "0.13.3" version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a46def7216d331efa51a6aa796ef777bfdfe9605378382827a553344b7e5eefc" checksum = "f7a68216437ef68f0738e48d6c7bb9e6e6a92237e001b03d838314b068f33c94"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"grass_compiler", "grass_compiler",
@ -669,9 +669,9 @@ dependencies = [
[[package]] [[package]]
name = "grass_compiler" name = "grass_compiler"
version = "0.13.3" version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f39216c1843182f78541276fec96f88406861f16aa19cc9f8add70f8e67b7577" checksum = "2d9e3df7f0222ce5184154973d247c591d9aadc28ce7a73c6cd31100c9facff6"
dependencies = [ dependencies = [
"codemap", "codemap",
"indexmap", "indexmap",

View file

@ -1,6 +1,8 @@
use hauchiwa::{HashedStyle, Mode, Sack}; use hauchiwa::{HashedStyle, Mode, Sack};
use hypertext::{html_elements, maud_move, Raw, Renderable}; use hypertext::{html_elements, maud_move, Raw, Renderable};
use crate::MyData;
const JS_RELOAD: &str = r#" const JS_RELOAD: &str = r#"
const socket = new WebSocket("ws://localhost:1337"); const socket = new WebSocket("ws://localhost:1337");
socket.addEventListener("message", (event) => { socket.addEventListener("message", (event) => {
@ -10,7 +12,7 @@ socket.addEventListener("message", (event) => {
"#; "#;
pub(crate) fn render_head<'s, 'r>( pub(crate) fn render_head<'s, 'r>(
sack: &'s Sack, sack: &'s Sack<MyData>,
title: String, title: String,
_styles: &'s [&str], _styles: &'s [&str],
scripts: Option<&'s [String]>, scripts: Option<&'s [String]>,
@ -64,7 +66,7 @@ fn render_style(style: &HashedStyle) -> impl Renderable + '_ {
} }
fn emit_tags_script<'a>( fn emit_tags_script<'a>(
sack: &'a Sack, sack: &'a Sack<MyData>,
scripts: &'a [String], scripts: &'a [String],
) -> Result<impl Renderable + 'a, String> { ) -> Result<impl Renderable + 'a, String> {
let tags = scripts let tags = scripts
@ -79,7 +81,10 @@ fn emit_tags_script<'a>(
)) ))
} }
fn emit_tag_script<'a>(sack: &'a Sack, script: &'a str) -> Result<impl Renderable + 'a, String> { fn emit_tag_script<'a>(
sack: &'a Sack<MyData>,
script: &'a str,
) -> Result<impl Renderable + 'a, String> {
let src = sack let src = sack
.get_script(script) .get_script(script)
.ok_or(format!("Missing script {script}"))?; .ok_or(format!("Missing script {script}"))?;

View file

@ -2,7 +2,7 @@ use camino::Utf8Path;
use hauchiwa::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, Link, LinkDate}; use crate::{html::Post, text::md::parse, Link, LinkDate, MyData};
const INTRO: &str = r#" const INTRO: &str = r#"
## ##
@ -16,7 +16,7 @@ const INTRO: &str = r#"
"#; "#;
fn intro(sack: &Sack) -> impl Renderable { fn intro(sack: &Sack<MyData>) -> impl Renderable {
let (parsed, _, _) = parse(INTRO, sack, "".into(), None); let (parsed, _, _) = parse(INTRO, sack, "".into(), None);
maud!( maud!(
section .p-card.intro-jp lang="ja-JP" { section .p-card.intro-jp lang="ja-JP" {
@ -40,7 +40,7 @@ fn photo() -> impl Renderable {
) )
} }
fn latest(sack: &Sack) -> impl Renderable { fn latest(sack: &Sack<MyData>) -> impl Renderable {
let links = { let links = {
let mut list = sack let mut list = sack
.get_meta::<Post>("**") .get_meta::<Post>("**")
@ -76,7 +76,7 @@ fn latest(sack: &Sack) -> impl Renderable {
) )
} }
pub(crate) fn home(sack: &Sack, main: &str) -> String { pub(crate) fn home(sack: &Sack<MyData>, main: &str) -> String {
let main = maud!( let main = maud!(
main .l-home { main .l-home {
article .l-home__article.markdown { article .l-home__article.markdown {

View file

@ -1,10 +1,9 @@
use hauchiwa::Sack;
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable}; use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
use crate::{html::page, LinkDate}; use crate::{html::page, LinkDate, MySack};
pub fn list<'s, 'g, 'html>( pub fn list<'s, 'g, 'html>(
sack: &'s Sack, sack: &'s MySack,
groups: &'g [(i32, Vec<LinkDate>)], groups: &'g [(i32, Vec<LinkDate>)],
title: String, title: String,
) -> Result<impl Renderable + 'html, String> ) -> Result<impl Renderable + 'html, String>

View file

@ -1,10 +1,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use camino::Utf8Path; use camino::Utf8Path;
use hauchiwa::{Outline, Sack}; use hauchiwa::Outline;
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable}; use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use crate::{html::Wiki, Link}; use crate::{html::Wiki, Link, MySack};
/// 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 {
@ -78,7 +78,7 @@ impl TreePage {
} }
/// 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: &MySack, glob: &str) -> impl Renderable {
let tree = let tree =
TreePage::from_iter( TreePage::from_iter(
sack.get_meta::<Wiki>(glob) sack.get_meta::<Wiki>(glob)

View file

@ -11,7 +11,7 @@ use std::collections::HashMap;
use camino::Utf8Path; use camino::Utf8Path;
use chrono::Datelike; use chrono::Datelike;
use hauchiwa::{Bibliography, Outline, Sack}; use hauchiwa::{Bibliography, Outline};
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;
@ -20,7 +20,7 @@ pub(crate) use post::Post;
pub(crate) use slideshow::Slideshow; pub(crate) use slideshow::Slideshow;
pub(crate) use wiki::Wiki; pub(crate) use wiki::Wiki;
use crate::LinkDate; use crate::{LinkDate, MySack};
fn navbar() -> impl Renderable { fn navbar() -> impl Renderable {
static ITEMS: &[(&str, &str)] = &[ static ITEMS: &[(&str, &str)] = &[
@ -68,16 +68,16 @@ fn navbar() -> impl Renderable {
) )
} }
pub fn footer<'s, 'html>(sack: &'s Sack) -> impl Renderable + 'html pub fn footer<'s, 'html>(sack: &'s MySack) -> impl Renderable + 'html
where where
's: 'html, 's: 'html,
{ {
let copy = format!("Copyright &copy; {} Maciej Jur", &sack.ctx.year); let copy = format!("Copyright &copy; {} Maciej Jur", &sack.ctx.data.year);
let mail = "maciej@kamoshi.org"; let mail = "maciej@kamoshi.org";
let href = format!("mailto:{}", mail); let href = format!("mailto:{}", mail);
let link = Utf8Path::new(&sack.ctx.link) let link = Utf8Path::new(&sack.ctx.data.link)
.join("src/commit") .join("src/commit")
.join(&sack.ctx.hash); .join(&sack.ctx.data.hash);
let link = match sack.get_file() { let link = match sack.get_file() {
Some(path) => link.join(path), Some(path) => link.join(path),
None => link, None => link,
@ -95,10 +95,10 @@ where
} }
div .repo { div .repo {
a href=(link.as_str()) { a href=(link.as_str()) {
(&sack.ctx.hash) (&sack.ctx.data.hash)
} }
div { div {
(&sack.ctx.date) (&sack.ctx.data.date)
} }
} }
a .right.footer__cc-wrap rel="license" href="http://creativecommons.org/licenses/by/4.0/" { a .right.footer__cc-wrap rel="license" href="http://creativecommons.org/licenses/by/4.0/" {
@ -109,7 +109,7 @@ where
} }
fn bare<'s, 'p, 'html>( fn bare<'s, 'p, 'html>(
sack: &'s Sack, sack: &'s MySack,
main: impl Renderable + 'p, main: impl Renderable + 'p,
title: String, title: String,
js: Option<&'s [String]>, js: Option<&'s [String]>,
@ -133,7 +133,7 @@ where
} }
fn full<'s, 'p, 'html>( fn full<'s, 'p, 'html>(
sack: &'s Sack, sack: &'s MySack,
main: impl Renderable + 'p, main: impl Renderable + 'p,
title: String, title: String,
) -> Result<impl Renderable + 'html, String> ) -> Result<impl Renderable + 'html, String>
@ -147,7 +147,7 @@ where
} }
fn page<'s, 'p, 'html>( fn page<'s, 'p, 'html>(
sack: &'s Sack, sack: &'s MySack,
main: impl Renderable + 'p, main: impl Renderable + 'p,
title: String, title: String,
js: Option<&'s [String]>, js: Option<&'s [String]>,
@ -161,7 +161,7 @@ where
bare(sack, main, title, js) bare(sack, main, title, js)
} }
pub(crate) fn to_list(sack: &Sack, list: Vec<LinkDate>, title: String) -> String { pub(crate) fn to_list(sack: &MySack, list: Vec<LinkDate>, title: String) -> String {
let mut groups = HashMap::<i32, Vec<_>>::new(); let mut groups = HashMap::<i32, Vec<_>>::new();
for page in list { for page in list {
@ -181,7 +181,7 @@ pub(crate) fn to_list(sack: &Sack, list: Vec<LinkDate>, title: String) -> String
list::list(sack, &groups, title).unwrap().render().into() list::list(sack, &groups, title).unwrap().render().into()
} }
pub(crate) fn map<'s, 'html>(sack: &'s Sack) -> Result<impl Renderable + 'html, String> pub(crate) fn map<'s, 'html>(sack: &'s MySack) -> Result<impl Renderable + 'html, String>
where where
's: 'html, 's: 'html,
{ {
@ -198,7 +198,7 @@ where
) )
} }
pub(crate) fn search(sack: &Sack) -> String { pub(crate) fn search(sack: &MySack) -> String {
page( page(
sack, sack,
maud!( maud!(
@ -215,7 +215,7 @@ pub(crate) fn search(sack: &Sack) -> String {
pub fn as_html( pub fn as_html(
meta: &Post, meta: &Post,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> String { ) -> String {
@ -225,7 +225,7 @@ pub fn as_html(
pub(crate) fn flox( pub(crate) fn flox(
title: &str, title: &str,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> String { ) -> String {

View file

@ -1,10 +1,12 @@
use camino::Utf8Path; use camino::Utf8Path;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Outline, Sack}; use hauchiwa::{Bibliography, Outline};
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;
use crate::MySack;
/// Represents a simple post. /// Represents a simple post.
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct Post { pub struct Post {
@ -17,7 +19,7 @@ pub struct Post {
pub fn parse_content( pub fn parse_content(
content: &str, content: &str,
sack: &Sack, sack: &MySack,
path: &Utf8Path, path: &Utf8Path,
library: Option<&Library>, library: Option<&Library>,
) -> (String, Outline, Bibliography) { ) -> (String, Outline, Bibliography) {
@ -27,7 +29,7 @@ pub fn parse_content(
pub fn as_html( pub fn as_html(
meta: &Post, meta: &Post,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> String { ) -> String {
@ -40,7 +42,7 @@ pub fn as_html(
pub fn post<'s, 'p, 'html>( pub fn post<'s, 'p, 'html>(
meta: &'p Post, meta: &'p Post,
parsed: &'p str, parsed: &'p str,
sack: &'s Sack, sack: &'s MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> Result<impl Renderable + 'html, String> ) -> Result<impl Renderable + 'html, String>
@ -60,7 +62,7 @@ where
pub fn article<'p, 's, 'html>( pub fn article<'p, 's, 'html>(
title: &'p str, title: &'p str,
parsed: &'p str, parsed: &'p str,
_: &'s Sack, _: &'s MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> impl Renderable + 'html ) -> impl Renderable + 'html

View file

@ -2,11 +2,13 @@ use std::fmt::Write;
use camino::Utf8Path; use camino::Utf8Path;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use hauchiwa::{Bibliography, Outline, Sack}; use hauchiwa::{Bibliography, Outline};
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;
use crate::MySack;
const CSS: &str = r#" const CSS: &str = r#"
.slides img { .slides img {
margin-left: auto; margin-left: auto;
@ -26,7 +28,7 @@ pub(crate) struct Slideshow {
pub fn parse_content( pub fn parse_content(
content: &str, content: &str,
sack: &Sack, sack: &MySack,
path: &Utf8Path, path: &Utf8Path,
library: Option<&Library>, library: Option<&Library>,
) -> (String, Outline, Bibliography) { ) -> (String, Outline, Bibliography) {
@ -57,14 +59,14 @@ pub fn parse_content(
pub fn as_html( pub fn as_html(
slides: &Slideshow, slides: &Slideshow,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
_: Outline, _: Outline,
_: Bibliography, _: Bibliography,
) -> String { ) -> String {
show(slides, sack, parsed) show(slides, sack, parsed)
} }
pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String { pub fn show(fm: &Slideshow, sack: &MySack, slides: &str) -> String {
crate::html::bare( crate::html::bare(
sack, sack,
maud!( maud!(

View file

@ -1,9 +1,11 @@
use camino::Utf8Path; use camino::Utf8Path;
use hauchiwa::{Bibliography, Outline, Sack}; use hauchiwa::{Bibliography, Outline};
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;
use crate::MySack;
/// Represents a wiki page /// Represents a wiki page
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct Wiki { pub struct Wiki {
@ -12,7 +14,7 @@ pub struct Wiki {
pub fn parse_content( pub fn parse_content(
content: &str, content: &str,
sack: &Sack, sack: &MySack,
path: &Utf8Path, path: &Utf8Path,
library: Option<&Library>, library: Option<&Library>,
) -> (String, Outline, Bibliography) { ) -> (String, Outline, Bibliography) {
@ -22,7 +24,7 @@ pub fn parse_content(
pub fn as_html( pub fn as_html(
meta: &Wiki, meta: &Wiki,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
outline: Outline, outline: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> String { ) -> String {
@ -32,7 +34,7 @@ pub fn as_html(
fn wiki( fn wiki(
matter: &Wiki, matter: &Wiki,
parsed: &str, parsed: &str,
sack: &Sack, sack: &MySack,
_: Outline, _: Outline,
bibliography: Bibliography, bibliography: Bibliography,
) -> String { ) -> String {

View file

@ -2,10 +2,12 @@ mod html;
mod text; mod text;
mod ts; mod ts;
use std::process::Command;
use camino::{Utf8Path, Utf8PathBuf}; use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Datelike, Utc};
use clap::{Parser, ValueEnum}; use clap::{Parser, ValueEnum};
use hauchiwa::{Collection, Processor, Website}; use hauchiwa::{Collection, Processor, Sack, Website};
use html::{Post, Slideshow, Wiki}; use html::{Post, Slideshow, Wiki};
use hypertext::Renderable; use hypertext::Renderable;
@ -22,29 +24,54 @@ enum Mode {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Link { struct MyData {
pub year: i32,
pub date: String,
pub link: String,
pub hash: String,
}
impl MyData {
fn new() -> Self {
let time = chrono::Utc::now();
Self {
year: time.year(),
date: time.format("%Y/%m/%d %H:%M").to_string(),
link: "https://git.kamoshi.org/kamov/website".into(),
hash: String::from_utf8(
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.expect("Couldn't load git revision")
.stdout,
)
.expect("Invalid UTF8")
.trim()
.into(),
}
}
}
type MySack<'a> = Sack<'a, MyData>;
#[derive(Debug, Clone)]
struct Link {
pub path: Utf8PathBuf, pub path: Utf8PathBuf,
pub name: String, pub name: String,
pub desc: Option<String>, pub desc: Option<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct LinkDate { struct LinkDate {
pub link: Link, pub link: Link,
pub date: DateTime<Utc>, 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();
let website = Website::design() let website = Website::design()
.add_loaders(vec![ .add_collections(vec![
Collection::glob_with::<Post>( Collection::glob_with::<Post>(
"content", "content",
"about.md", "about.md",
@ -91,11 +118,13 @@ fn main() {
}, },
), ),
]) ])
.js("search", "./js/search/dist/search.js") .add_scripts(vec![
.js("photos", "./js/vanilla/photos.js") ("search", "./js/search/dist/search.js"),
.js("reveal", "./js/vanilla/reveal.js") ("photos", "./js/vanilla/photos.js"),
.js("editor", "./js/flox/main.ts") ("reveal", "./js/vanilla/reveal.js"),
.js("lambda", "./js/flox/lambda.ts") ("editor", "./js/flox/main.ts"),
("lambda", "./js/flox/lambda.ts"),
])
.add_virtual( .add_virtual(
|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(),
@ -172,7 +201,7 @@ fn main() {
.finish(); .finish();
match args.mode { match args.mode {
Mode::Build => website.build(), Mode::Build => website.build(MyData::new()),
Mode::Watch => website.watch(), Mode::Watch => website.watch(MyData::new()),
} }
} }

View file

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use camino::Utf8Path; use camino::Utf8Path;
use hauchiwa::{Bibliography, Outline, Sack}; use hauchiwa::{Bibliography, Outline};
use hayagriva::{ use hayagriva::{
archive::ArchivedStyle, archive::ArchivedStyle,
citationberg::{IndependentStyle, Locale, Style}, citationberg::{IndependentStyle, Locale, Style},
@ -13,7 +13,7 @@ use once_cell::sync::Lazy;
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream}; use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream};
use regex::Regex; use regex::Regex;
use crate::ts; use crate::{ts, MySack};
static OPTS: Lazy<Options> = Lazy::new(|| { static OPTS: Lazy<Options> = Lazy::new(|| {
Options::empty() Options::empty()
@ -51,7 +51,7 @@ static STYLE: Lazy<IndependentStyle> =
pub fn parse( pub fn parse(
content: &str, content: &str,
sack: &Sack, sack: &MySack,
path: &Utf8Path, path: &Utf8Path,
library: Option<&Library>, library: Option<&Library>,
) -> (String, Outline, Bibliography) { ) -> (String, Outline, Bibliography) {
@ -353,7 +353,7 @@ fn make_emoji(event: Event) -> Event {
} }
} }
fn swap_hashed_image<'a>(dir: &'a Utf8Path, sack: &'a Sack) -> impl Fn(Event) -> Event + 'a { fn swap_hashed_image<'a>(dir: &'a Utf8Path, sack: &'a MySack) -> impl Fn(Event) -> Event + 'a {
move |event| match event { move |event| match event {
Event::Start(start) => match start { Event::Start(start) => match start {
Tag::Image { Tag::Image {