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.

55 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. 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. ("rss.xml", include_str!("builtins/rss.xml")),
  22. ("sitemap.xml", include_str!("builtins/sitemap.xml")),
  23. ("robots.txt", include_str!("builtins/robots.txt")),
  24. ("anchor-link.html", include_str!("builtins/anchor-link.html")),
  25. ("shortcodes/youtube.html", include_str!("builtins/shortcodes/youtube.html")),
  26. ("shortcodes/vimeo.html", include_str!("builtins/shortcodes/vimeo.html")),
  27. ("shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
  28. ("shortcodes/streamable.html", include_str!("builtins/shortcodes/streamable.html")),
  29. ("internal/alias.html", include_str!("builtins/internal/alias.html")),
  30. ]).unwrap();
  31. tera.register_filter("markdown", filters::markdown);
  32. tera.register_filter("base64_encode", filters::base64_encode);
  33. tera.register_filter("base64_decode", filters::base64_decode);
  34. tera
  35. };
  36. }
  37. /// Renders the `internal/alias.html` template that will redirect
  38. /// via refresh to the url given
  39. pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
  40. let mut context = Context::new();
  41. context.add("url", &url);
  42. tera.render("internal/alias.html", &context)
  43. .chain_err(|| format!("Failed to render alias for '{}'", url))
  44. }