add: text and icon plugins (bberry)
This commit is contained in:
parent
350e47f4b7
commit
7de2c2e935
5 changed files with 78 additions and 38 deletions
|
@ -1,4 +1,7 @@
|
|||
use bberry::core::element::Render;
|
||||
use bberry::{
|
||||
core::element::{Element, Render},
|
||||
text, read_param,
|
||||
};
|
||||
use pathbufd::PathBufD;
|
||||
use regex::Regex;
|
||||
use std::{
|
||||
|
@ -168,7 +171,12 @@ macro_rules! vendor_icon {
|
|||
/// * icons
|
||||
/// * icons (with class specifier)
|
||||
/// * l10n text
|
||||
pub(crate) async fn replace_in_html(input: &str, config: &Config, lisp: bool) -> String {
|
||||
pub(crate) async fn replace_in_html(
|
||||
input: &str,
|
||||
config: &Config,
|
||||
lisp: bool,
|
||||
plugins: Option<&mut HashMap<String, Box<dyn FnMut(Element) -> Element>>>,
|
||||
) -> String {
|
||||
let reader = HTML_FOOTER.read().await;
|
||||
|
||||
if reader.is_empty() {
|
||||
|
@ -190,7 +198,11 @@ pub(crate) async fn replace_in_html(input: &str, config: &Config, lisp: bool) ->
|
|||
let mut input = if !lisp {
|
||||
input.to_string()
|
||||
} else {
|
||||
bberry::parse(input).0.render()
|
||||
if let Some(plugins) = plugins {
|
||||
bberry::parse(input).render(plugins)
|
||||
} else {
|
||||
bberry::parse(input).render_safe()
|
||||
}
|
||||
};
|
||||
|
||||
input = input.replace("<!-- prettier-ignore -->", "");
|
||||
|
@ -243,21 +255,49 @@ pub(crate) async fn replace_in_html(input: &str, config: &Config, lisp: bool) ->
|
|||
input
|
||||
}
|
||||
|
||||
pub(crate) fn lisp_plugins() -> HashMap<String, Box<dyn FnMut(Element) -> Element>> {
|
||||
let mut plugins = HashMap::new();
|
||||
|
||||
plugins.insert(
|
||||
"icon".to_string(),
|
||||
Box::new(|e: Element| text!(format!("{{{{ icon \"{}\" }}}}", read_param!(e, 0)))) as _,
|
||||
);
|
||||
|
||||
plugins.insert(
|
||||
"icon_class".to_string(),
|
||||
Box::new(|e: Element| {
|
||||
text!(format!(
|
||||
"{{{{ icon \"{}\" c({}) }}}}",
|
||||
read_param!(e, 0),
|
||||
read_param!(e, 1)
|
||||
))
|
||||
}) as _,
|
||||
);
|
||||
|
||||
plugins.insert(
|
||||
"str".to_string(),
|
||||
Box::new(|e: Element| text!(format!("{{{{ text \"{}\" }}}}", read_param!(e, 0)))) as _,
|
||||
);
|
||||
|
||||
plugins
|
||||
}
|
||||
|
||||
/// Set up public directories.
|
||||
pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
||||
vendor_icon!("spotify", VENDOR_SPOTIFY_ICON, config.dirs.icons);
|
||||
vendor_icon!("last_fm", VENDOR_LAST_FM_ICON, config.dirs.icons);
|
||||
|
||||
// ...
|
||||
let mut plugins = lisp_plugins();
|
||||
let html_path = PathBufD::current().join(&config.dirs.templates);
|
||||
|
||||
write_template!(html_path->"root.html"(crate::assets::ROOT) --config=config --lisp);
|
||||
write_template!(html_path->"root.html"(crate::assets::ROOT) --config=config --lisp plugins);
|
||||
write_template!(html_path->"macros.html"(crate::assets::MACROS) --config=config);
|
||||
write_template!(html_path->"components.html"(crate::assets::COMPONENTS) --config=config);
|
||||
|
||||
write_template!(html_path->"misc/error.html"(crate::assets::MISC_ERROR) -d "misc" --config=config --lisp);
|
||||
write_template!(html_path->"misc/error.html"(crate::assets::MISC_ERROR) -d "misc" --config=config --lisp plugins);
|
||||
write_template!(html_path->"misc/notifications.html"(crate::assets::MISC_NOTIFICATIONS) --config=config);
|
||||
write_template!(html_path->"misc/markdown.html"(crate::assets::MISC_MARKDOWN) --config=config --lisp);
|
||||
write_template!(html_path->"misc/markdown.html"(crate::assets::MISC_MARKDOWN) --config=config --lisp plugins);
|
||||
write_template!(html_path->"misc/requests.html"(crate::assets::MISC_REQUESTS) --config=config);
|
||||
|
||||
write_template!(html_path->"auth/base.html"(crate::assets::AUTH_BASE) -d "auth" --config=config);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue