mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-05-09 18:16:43 -07:00
add very basic clicker game
This commit is contained in:
parent
3ccd5b0df8
commit
19ffac4a90
9 changed files with 335 additions and 17 deletions
|
@ -5,17 +5,46 @@ use crate::{blog::BlogPostMetadata, builder::SiteBuilder, resource::ResourceTemp
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum Extra {
|
||||
Basic(&'static str),
|
||||
HtmlModification(fn(page: String, builder: &SiteBuilder) -> eyre::Result<String>),
|
||||
}
|
||||
|
||||
impl Extra {
|
||||
/// runs the handler for the extra
|
||||
pub fn handle(&self, page: String, builder: &SiteBuilder) -> eyre::Result<String> {
|
||||
match self {
|
||||
Self::Basic(template) => {
|
||||
println!("{template}");
|
||||
let content = builder.reg.render(template, &())?;
|
||||
append_to(&page, &content, "main.page")
|
||||
}
|
||||
Self::HtmlModification(f) => (f)(page, builder),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the extra for the given value.
|
||||
pub fn get_extra(extra: &str) -> Option<Extra> {
|
||||
match extra {
|
||||
"index" => Some(Extra::HtmlModification(index)),
|
||||
"click" => Some(Extra::Basic("extras/click")),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn append_to(page: &str, content: &str, selector: &str) -> eyre::Result<String> {
|
||||
Ok(lol_html::rewrite_str(
|
||||
page,
|
||||
RewriteStrSettings {
|
||||
element_content_handlers: vec![element!(selector, move |el| {
|
||||
el.append(content, lol_html::html_content::ContentType::Html);
|
||||
Ok(())
|
||||
})],
|
||||
..Default::default()
|
||||
},
|
||||
)?)
|
||||
}
|
||||
|
||||
/// Extra to add a sidebar to the index page with recent blog posts on it.
|
||||
fn index(page: String, builder: &SiteBuilder) -> eyre::Result<String> {
|
||||
#[derive(Debug, Serialize)]
|
||||
|
@ -42,14 +71,5 @@ fn index(page: String, builder: &SiteBuilder) -> eyre::Result<String> {
|
|||
},
|
||||
)?;
|
||||
|
||||
Ok(lol_html::rewrite_str(
|
||||
&page,
|
||||
RewriteStrSettings {
|
||||
element_content_handlers: vec![element!("#content", move |el| {
|
||||
el.append(&sidebar, lol_html::html_content::ContentType::Html);
|
||||
Ok(())
|
||||
})],
|
||||
..Default::default()
|
||||
},
|
||||
)?)
|
||||
append_to(&page, &sidebar, "#content")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue