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.

53 lines
1.7KB

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