2017-07-01 07:47:41 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate tera;
|
|
|
|
extern crate base64;
|
2018-10-18 15:32:30 +00:00
|
|
|
extern crate csv;
|
2018-10-31 07:18:57 +00:00
|
|
|
extern crate pulldown_cmark;
|
2018-10-29 19:13:09 +00:00
|
|
|
extern crate reqwest;
|
|
|
|
extern crate url;
|
2019-05-30 18:06:24 +00:00
|
|
|
extern crate image;
|
2018-10-18 15:32:30 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
|
|
|
#[cfg(not(test))]
|
|
|
|
extern crate serde_json;
|
2017-05-13 04:05:38 +00:00
|
|
|
|
2017-08-07 11:38:13 +00:00
|
|
|
extern crate config;
|
2018-10-31 07:18:57 +00:00
|
|
|
extern crate errors;
|
2018-02-02 20:35:04 +00:00
|
|
|
extern crate imageproc;
|
2018-10-31 07:18:57 +00:00
|
|
|
extern crate library;
|
|
|
|
extern crate utils;
|
2017-05-12 14:27:22 +00:00
|
|
|
|
|
|
|
pub mod filters;
|
|
|
|
pub mod global_fns;
|
|
|
|
|
2018-10-31 07:18:57 +00:00
|
|
|
use tera::{Context, Tera};
|
2017-07-01 07:47:41 +00:00
|
|
|
|
2019-02-09 18:54:46 +00:00
|
|
|
use errors::{Error, Result};
|
2017-07-01 07:47:41 +00:00
|
|
|
|
2017-05-12 14:27:22 +00:00
|
|
|
lazy_static! {
|
2018-10-18 20:50:06 +00:00
|
|
|
pub static ref ZOLA_TERA: Tera = {
|
2017-05-12 14:27:22 +00:00
|
|
|
let mut tera = Tera::default();
|
|
|
|
tera.add_raw_templates(vec![
|
2019-01-16 09:59:29 +00:00
|
|
|
("__zola_builtins/404.html", include_str!("builtins/404.html")),
|
|
|
|
("__zola_builtins/rss.xml", include_str!("builtins/rss.xml")),
|
|
|
|
("__zola_builtins/sitemap.xml", include_str!("builtins/sitemap.xml")),
|
|
|
|
("__zola_builtins/robots.txt", include_str!("builtins/robots.txt")),
|
2019-03-16 09:01:11 +00:00
|
|
|
(
|
|
|
|
"__zola_builtins/split_sitemap_index.xml",
|
|
|
|
include_str!("builtins/split_sitemap_index.xml"),
|
|
|
|
),
|
2019-03-14 19:57:22 +00:00
|
|
|
("__zola_builtins/anchor-link.html", include_str!("builtins/anchor-link.html")),
|
2019-01-16 09:59:29 +00:00
|
|
|
(
|
|
|
|
"__zola_builtins/shortcodes/youtube.html",
|
|
|
|
include_str!("builtins/shortcodes/youtube.html"),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"__zola_builtins/shortcodes/vimeo.html",
|
|
|
|
include_str!("builtins/shortcodes/vimeo.html"),
|
|
|
|
),
|
|
|
|
("__zola_builtins/shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
|
|
|
|
(
|
|
|
|
"__zola_builtins/shortcodes/streamable.html",
|
|
|
|
include_str!("builtins/shortcodes/streamable.html"),
|
|
|
|
),
|
2017-05-12 14:27:22 +00:00
|
|
|
("internal/alias.html", include_str!("builtins/internal/alias.html")),
|
2018-10-31 07:18:57 +00:00
|
|
|
])
|
|
|
|
.unwrap();
|
2017-05-13 02:45:29 +00:00
|
|
|
tera.register_filter("markdown", filters::markdown);
|
|
|
|
tera.register_filter("base64_encode", filters::base64_encode);
|
|
|
|
tera.register_filter("base64_decode", filters::base64_decode);
|
2017-05-12 14:27:22 +00:00
|
|
|
tera
|
|
|
|
};
|
|
|
|
}
|
2017-05-13 04:05:38 +00:00
|
|
|
|
|
|
|
/// Renders the `internal/alias.html` template that will redirect
|
|
|
|
/// via refresh to the url given
|
|
|
|
pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
|
|
|
|
let mut context = Context::new();
|
2018-09-09 17:43:14 +00:00
|
|
|
context.insert("url", &url);
|
2017-05-13 04:05:38 +00:00
|
|
|
|
2019-01-23 18:20:02 +00:00
|
|
|
tera.render("internal/alias.html", context)
|
2019-01-11 19:29:46 +00:00
|
|
|
.map_err(|e| Error::chain(format!("Failed to render alias for '{}'", url), e))
|
2017-05-13 04:05:38 +00:00
|
|
|
}
|