2017-07-01 07:47:41 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate tera;
|
|
|
|
extern crate base64;
|
|
|
|
extern crate pulldown_cmark;
|
2018-10-18 15:32:30 +00:00
|
|
|
extern crate csv;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
|
|
|
#[cfg(not(test))]
|
|
|
|
extern crate serde_json;
|
2017-05-13 04:05:38 +00:00
|
|
|
|
2017-07-01 07:47:41 +00:00
|
|
|
extern crate errors;
|
|
|
|
extern crate utils;
|
2018-10-02 14:42:34 +00:00
|
|
|
extern crate library;
|
2017-08-07 11:38:13 +00:00
|
|
|
extern crate config;
|
2018-02-02 20:35:04 +00:00
|
|
|
extern crate imageproc;
|
2017-05-12 14:27:22 +00:00
|
|
|
|
|
|
|
pub mod filters;
|
|
|
|
pub mod global_fns;
|
|
|
|
|
2017-07-01 07:47:41 +00:00
|
|
|
use tera::{Tera, Context};
|
|
|
|
|
2017-08-23 10:17:24 +00:00
|
|
|
use errors::{Result, ResultExt};
|
2017-07-01 07:47:41 +00:00
|
|
|
|
2017-05-12 14:27:22 +00:00
|
|
|
lazy_static! {
|
|
|
|
pub static ref GUTENBERG_TERA: Tera = {
|
|
|
|
let mut tera = Tera::default();
|
|
|
|
tera.add_raw_templates(vec![
|
2018-06-26 06:24:57 +00:00
|
|
|
("404.html", include_str!("builtins/404.html")),
|
2017-05-12 14:27:22 +00:00
|
|
|
("rss.xml", include_str!("builtins/rss.xml")),
|
|
|
|
("sitemap.xml", include_str!("builtins/sitemap.xml")),
|
|
|
|
("robots.txt", include_str!("builtins/robots.txt")),
|
|
|
|
("anchor-link.html", include_str!("builtins/anchor-link.html")),
|
|
|
|
|
|
|
|
("shortcodes/youtube.html", include_str!("builtins/shortcodes/youtube.html")),
|
|
|
|
("shortcodes/vimeo.html", include_str!("builtins/shortcodes/vimeo.html")),
|
|
|
|
("shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
|
2017-06-06 03:51:20 +00:00
|
|
|
("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")),
|
|
|
|
]).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
|
|
|
|
|
|
|
tera.render("internal/alias.html", &context)
|
|
|
|
.chain_err(|| format!("Failed to render alias for '{}'", url))
|
|
|
|
}
|