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.

56 lines
1.8KB

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