You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0KB

  1. #[macro_use]
  2. extern crate lazy_static;
  3. #[macro_use]
  4. extern crate tera;
  5. extern crate base64;
  6. extern crate csv;
  7. extern crate pulldown_cmark;
  8. extern crate reqwest;
  9. extern crate url;
  10. #[cfg(test)]
  11. #[macro_use]
  12. extern crate serde_json;
  13. #[cfg(not(test))]
  14. extern crate serde_json;
  15. extern crate config;
  16. extern crate errors;
  17. extern crate imageproc;
  18. extern crate library;
  19. extern crate utils;
  20. pub mod filters;
  21. pub mod global_fns;
  22. use tera::{Context, Tera};
  23. use errors::{Result, ResultExt};
  24. lazy_static! {
  25. pub static ref ZOLA_TERA: Tera = {
  26. let mut tera = Tera::default();
  27. tera.add_raw_templates(vec![
  28. ("404.html", include_str!("builtins/404.html")),
  29. ("rss.xml", include_str!("builtins/rss.xml")),
  30. ("sitemap.xml", include_str!("builtins/sitemap.xml")),
  31. ("robots.txt", include_str!("builtins/robots.txt")),
  32. ("anchor-link.html", include_str!("builtins/anchor-link.html")),
  33. ("shortcodes/youtube.html", include_str!("builtins/shortcodes/youtube.html")),
  34. ("shortcodes/vimeo.html", include_str!("builtins/shortcodes/vimeo.html")),
  35. ("shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
  36. ("shortcodes/streamable.html", include_str!("builtins/shortcodes/streamable.html")),
  37. ("internal/alias.html", include_str!("builtins/internal/alias.html")),
  38. ])
  39. .unwrap();
  40. tera.register_filter("markdown", filters::markdown);
  41. tera.register_filter("base64_encode", filters::base64_encode);
  42. tera.register_filter("base64_decode", filters::base64_decode);
  43. tera
  44. };
  45. }
  46. /// Renders the `internal/alias.html` template that will redirect
  47. /// via refresh to the url given
  48. pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
  49. let mut context = Context::new();
  50. context.insert("url", &url);
  51. tera.render("internal/alias.html", &context)
  52. .chain_err(|| format!("Failed to render alias for '{}'", url))
  53. }