2020-07-24 21:44:00 +00:00
|
|
|
use crate::Site;
|
2021-02-19 19:51:08 +00:00
|
|
|
use templates::{filters, global_fns};
|
|
|
|
use tera::Result as TeraResult;
|
2020-07-24 21:44:00 +00:00
|
|
|
|
|
|
|
/// Adds global fns that are to be available to shortcodes while rendering markdown
|
2021-02-19 19:51:08 +00:00
|
|
|
pub fn register_early_global_fns(site: &mut Site) -> TeraResult<()> {
|
2021-02-02 19:49:57 +00:00
|
|
|
site.tera.register_filter(
|
|
|
|
"markdown",
|
2021-02-19 19:51:08 +00:00
|
|
|
filters::MarkdownFilter::new(
|
|
|
|
site.base_path.clone(),
|
|
|
|
site.config.clone(),
|
|
|
|
site.permalinks.clone(),
|
|
|
|
)?,
|
2021-02-02 19:49:57 +00:00
|
|
|
);
|
2020-11-28 12:04:49 +00:00
|
|
|
|
2020-07-24 21:44:00 +00:00
|
|
|
site.tera.register_function(
|
|
|
|
"get_url",
|
|
|
|
global_fns::GetUrl::new(
|
|
|
|
site.config.clone(),
|
|
|
|
site.permalinks.clone(),
|
|
|
|
vec![site.static_path.clone(), site.output_path.clone(), site.content_path.clone()],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
site.tera
|
|
|
|
.register_function("resize_image", global_fns::ResizeImage::new(site.imageproc.clone()));
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_image_metadata",
|
|
|
|
global_fns::GetImageMeta::new(site.content_path.clone()),
|
|
|
|
);
|
|
|
|
site.tera.register_function("load_data", global_fns::LoadData::new(site.base_path.clone()));
|
|
|
|
site.tera.register_function("trans", global_fns::Trans::new(site.config.clone()));
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_taxonomy_url",
|
2020-09-02 09:40:06 +00:00
|
|
|
global_fns::GetTaxonomyUrl::new(
|
|
|
|
&site.config.default_language,
|
|
|
|
&site.taxonomies,
|
|
|
|
site.config.slugify.taxonomies,
|
|
|
|
),
|
2020-07-24 21:44:00 +00:00
|
|
|
);
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_file_hash",
|
|
|
|
global_fns::GetFileHash::new(vec![
|
|
|
|
site.static_path.clone(),
|
|
|
|
site.output_path.clone(),
|
|
|
|
site.content_path.clone(),
|
|
|
|
]),
|
|
|
|
);
|
2021-02-19 19:51:08 +00:00
|
|
|
|
|
|
|
Ok(())
|
2020-07-24 21:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Functions filled once we have parsed all the pages/sections only, so not available in shortcodes
|
|
|
|
pub fn register_tera_global_fns(site: &mut Site) {
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_page",
|
|
|
|
global_fns::GetPage::new(site.base_path.clone(), site.library.clone()),
|
|
|
|
);
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_section",
|
|
|
|
global_fns::GetSection::new(site.base_path.clone(), site.library.clone()),
|
|
|
|
);
|
|
|
|
site.tera.register_function(
|
|
|
|
"get_taxonomy",
|
|
|
|
global_fns::GetTaxonomy::new(
|
|
|
|
&site.config.default_language,
|
|
|
|
site.taxonomies.clone(),
|
|
|
|
site.library.clone(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|