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
1.9KB

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