error handling
This commit is contained in:
parent
771eb8cc85
commit
cf2754c405
|
@ -14,7 +14,7 @@ pub(crate) fn render_head<'s, 'r>(
|
|||
title: String,
|
||||
styles: &'s [&str],
|
||||
scripts: Option<&'s [String]>,
|
||||
) -> impl Renderable + 'r
|
||||
) -> Result<impl Renderable + 'r, String>
|
||||
where
|
||||
's: 'r,
|
||||
{
|
||||
|
@ -23,7 +23,12 @@ where
|
|||
let css_r = sack.get_style("reveal").expect("Missing styles");
|
||||
let css_p = sack.get_style("leaflet").expect("Missing styles");
|
||||
|
||||
maud_move!(
|
||||
let scripts = match scripts {
|
||||
Some(scripts) => Some(emit_tags_script(sack, scripts)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok(maud_move!(
|
||||
meta charset="utf-8";
|
||||
meta name="viewport" content="width=device-width, initial-scale=1";
|
||||
title {
|
||||
|
@ -47,11 +52,9 @@ where
|
|||
}
|
||||
|
||||
@if let Some(scripts) = scripts {
|
||||
@for script in scripts {
|
||||
(emit_tag_script(sack, script))
|
||||
(scripts)
|
||||
}
|
||||
}
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn render_style(style: &HashedStyle) -> impl Renderable + '_ {
|
||||
|
@ -60,10 +63,23 @@ fn render_style(style: &HashedStyle) -> impl Renderable + '_ {
|
|||
)
|
||||
}
|
||||
|
||||
fn emit_tag_script<'a>(sack: &'a Sack, script: &'a str) -> impl Renderable + 'a {
|
||||
let src = sack.get_script(script).unwrap().path.as_str();
|
||||
fn emit_tags_script<'a>(sack: &'a Sack, scripts: &'a [String]) -> Result<impl Renderable + 'a, String> {
|
||||
let tags = scripts
|
||||
.iter()
|
||||
.map(|script| emit_tag_script(sack, script))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
maud_move!(
|
||||
script type="module" src=(src) defer {}
|
||||
)
|
||||
Ok(maud_move!(
|
||||
@for tag in tags {
|
||||
(tag)
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
fn emit_tag_script<'a>(sack: &'a Sack, script: &'a str) -> Result<impl Renderable + 'a, String> {
|
||||
let src = sack
|
||||
.get_script(script)
|
||||
.ok_or(format!("Missing script {script}"))?;
|
||||
|
||||
Ok(maud_move!(script type="module" src=(src.path.as_str()) defer {}))
|
||||
}
|
||||
|
|
|
@ -81,5 +81,5 @@ pub(crate) fn home(sack: &Sack, main: &str) -> String {
|
|||
}
|
||||
);
|
||||
|
||||
crate::html::page(sack, main, "Home".into(), None).render().into()
|
||||
crate::html::page(sack, main, "Home".into(), None).unwrap().render().into()
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ pub fn list<'s, 'g, 'html>(
|
|||
sack: &'s Sack,
|
||||
groups: &'g [(i32, Vec<LinkDate>)],
|
||||
title: String,
|
||||
) -> impl Renderable + 'html
|
||||
) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
'g: 'html,
|
||||
|
|
|
@ -114,21 +114,23 @@ fn bare<'s, 'p, 'html>(
|
|||
main: impl Renderable + 'p,
|
||||
title: String,
|
||||
js: Option<&'s [String]>,
|
||||
) -> impl Renderable + 'html
|
||||
) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
'p: 'html,
|
||||
{
|
||||
maud_move!(
|
||||
let head = head::render_head(sack, title, &[], js)?;
|
||||
|
||||
Ok(maud_move!(
|
||||
(Raw("<!DOCTYPE html>"))
|
||||
html lang="en" {
|
||||
(head::render_head(sack, title, &[], js))
|
||||
(head)
|
||||
|
||||
body {
|
||||
(main)
|
||||
}
|
||||
}
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,7 +138,7 @@ fn full<'s, 'p, 'html>(
|
|||
sack: &'s Sack,
|
||||
main: impl Renderable + 'p,
|
||||
title: String,
|
||||
) -> impl Renderable + 'html
|
||||
) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
'p: 'html,
|
||||
|
@ -154,7 +156,7 @@ fn page<'s, 'p, 'html>(
|
|||
main: impl Renderable + 'p,
|
||||
title: String,
|
||||
js: Option<&'s [String]>,
|
||||
) -> impl Renderable + 'html
|
||||
) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
'p: 'html,
|
||||
|
@ -185,10 +187,10 @@ pub(crate) fn to_list(sack: &Sack, list: Vec<LinkDate>, title: String) -> String
|
|||
|
||||
groups.sort_by(|a, b| b.0.cmp(&a.0));
|
||||
|
||||
list::list(sack, &groups, title).render().into()
|
||||
list::list(sack, &groups, title).unwrap().render().into()
|
||||
}
|
||||
|
||||
pub(crate) fn map<'s, 'html>(sack: &'s Sack) -> impl Renderable + 'html
|
||||
pub(crate) fn map<'s, 'html>(sack: &'s Sack) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
{
|
||||
|
@ -214,6 +216,7 @@ pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String {
|
|||
String::from("Search"),
|
||||
Some(&["search".into()])
|
||||
)
|
||||
.unwrap()
|
||||
.render()
|
||||
.into()
|
||||
}
|
||||
|
@ -292,6 +295,7 @@ pub(crate) fn flox<'p, 's, 'html>(
|
|||
String::from("Flox"),
|
||||
Some(&["editor".into()])
|
||||
)
|
||||
.unwrap()
|
||||
.render()
|
||||
.into()
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ impl Content for Post {
|
|||
bibliography: Bibliography,
|
||||
) -> String {
|
||||
post(self, parsed, sack, outline, bibliography)
|
||||
.unwrap()
|
||||
.render()
|
||||
.into()
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ pub fn post<'s, 'p, 'html>(
|
|||
sack: &'s Sack,
|
||||
outline: Outline,
|
||||
bibliography: Bibliography,
|
||||
) -> impl Renderable + 'html
|
||||
) -> Result<impl Renderable + 'html, String>
|
||||
where
|
||||
's: 'html,
|
||||
'p: 'html,
|
||||
|
|
|
@ -82,6 +82,7 @@ pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String {
|
|||
fm.title.clone(),
|
||||
Some(&["reveal".into()])
|
||||
)
|
||||
.unwrap()
|
||||
.render()
|
||||
.into()
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ fn wiki(
|
|||
);
|
||||
|
||||
crate::html::page(sack, main, matter.title.to_owned(), None)
|
||||
.unwrap()
|
||||
.render()
|
||||
.into()
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ fn main() {
|
|||
.js("editor", "./js/flox/main.ts")
|
||||
.js("lambda", "./js/flox/lambda.ts")
|
||||
.add_virtual(
|
||||
|sack| crate::html::map(sack).render().to_owned().into(),
|
||||
|sack| crate::html::map(sack).unwrap().render().to_owned().into(),
|
||||
"map/index.html".into(),
|
||||
)
|
||||
.add_virtual(
|
||||
|
|
Loading…
Reference in a new issue