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.

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