2024-07-22 23:08:11 +02:00
|
|
|
use camino::{Utf8Path, Utf8PathBuf};
|
2024-07-03 23:34:31 +02:00
|
|
|
use chrono::{DateTime, Utc};
|
2024-09-15 01:44:37 +02:00
|
|
|
use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack};
|
2024-07-03 23:34:31 +02:00
|
|
|
use hayagriva::Library;
|
2024-07-22 23:08:11 +02:00
|
|
|
use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable};
|
2024-07-03 23:34:31 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
2024-07-05 13:59:07 +02:00
|
|
|
const CSS: &str = r#"
|
|
|
|
.slides img {
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
max-height: 60vh;
|
|
|
|
}
|
|
|
|
"#;
|
2024-07-03 23:34:31 +02:00
|
|
|
|
|
|
|
/// Represents a slideshow
|
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
|
|
|
pub(crate) struct Slideshow {
|
2024-09-15 01:44:37 +02:00
|
|
|
pub title: String,
|
|
|
|
#[serde(with = "super::isodate")]
|
|
|
|
pub date: DateTime<Utc>,
|
|
|
|
pub desc: Option<String>,
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn parse_content(
|
|
|
|
content: &str,
|
|
|
|
sack: &Sack,
|
|
|
|
path: &Utf8Path,
|
|
|
|
library: Option<&Library>,
|
|
|
|
) -> (String, Outline, Bibliography) {
|
|
|
|
let parsed = content
|
|
|
|
.split("\n-----\n")
|
|
|
|
.map(|chunk| {
|
|
|
|
chunk
|
|
|
|
.split("\n---\n")
|
|
|
|
.map(|slide| crate::text::md::parse(&slide, sack, path, library).0)
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
})
|
|
|
|
.map(|stack| match stack.len() > 1 {
|
|
|
|
true => format!(
|
|
|
|
"<section>{}</section>",
|
|
|
|
stack
|
|
|
|
.into_iter()
|
|
|
|
.map(|slide| format!("<section>{slide}</section>"))
|
|
|
|
.collect::<String>()
|
|
|
|
),
|
|
|
|
false => format!("<section>{}</section>", stack[0]),
|
|
|
|
})
|
|
|
|
.collect::<String>();
|
|
|
|
(parsed, Outline(vec![]), Bibliography(None))
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn as_html(
|
|
|
|
slides: &Slideshow,
|
|
|
|
parsed: &str,
|
|
|
|
sack: &Sack,
|
|
|
|
_: Outline,
|
|
|
|
_: Bibliography,
|
|
|
|
) -> String {
|
|
|
|
show(slides, sack, parsed)
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
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(),
|
|
|
|
}))
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|
|
|
|
|
2024-07-22 23:08:11 +02:00
|
|
|
pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
|
2024-09-15 01:44:37 +02:00
|
|
|
crate::html::bare(
|
|
|
|
sack,
|
|
|
|
maud!(
|
|
|
|
div .reveal {
|
|
|
|
div .slides {
|
|
|
|
(Raw(slides))
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
style { (Raw(CSS)) }
|
|
|
|
),
|
|
|
|
fm.title.clone(),
|
|
|
|
Some(&["reveal".into()]),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.render()
|
|
|
|
.into()
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|