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.

lib.rs 2.4KB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #[macro_use]
  2. extern crate lazy_static;
  3. #[macro_use]
  4. extern crate tera;
  5. extern crate base64;
  6. extern crate csv;
  7. extern crate image;
  8. extern crate pulldown_cmark;
  9. extern crate reqwest;
  10. extern crate url;
  11. #[cfg(test)]
  12. #[macro_use]
  13. extern crate serde_json;
  14. #[cfg(not(test))]
  15. extern crate serde_json;
  16. extern crate config;
  17. extern crate errors;
  18. extern crate imageproc;
  19. extern crate library;
  20. extern crate utils;
  21. pub mod filters;
  22. pub mod global_fns;
  23. use tera::{Context, Tera};
  24. use errors::{Error, Result};
  25. lazy_static! {
  26. pub static ref ZOLA_TERA: Tera = {
  27. let mut tera = Tera::default();
  28. tera.add_raw_templates(vec![
  29. ("__zola_builtins/404.html", include_str!("builtins/404.html")),
  30. ("__zola_builtins/rss.xml", include_str!("builtins/rss.xml")),
  31. ("__zola_builtins/sitemap.xml", include_str!("builtins/sitemap.xml")),
  32. ("__zola_builtins/robots.txt", include_str!("builtins/robots.txt")),
  33. (
  34. "__zola_builtins/split_sitemap_index.xml",
  35. include_str!("builtins/split_sitemap_index.xml"),
  36. ),
  37. ("__zola_builtins/anchor-link.html", include_str!("builtins/anchor-link.html")),
  38. (
  39. "__zola_builtins/shortcodes/youtube.html",
  40. include_str!("builtins/shortcodes/youtube.html"),
  41. ),
  42. (
  43. "__zola_builtins/shortcodes/vimeo.html",
  44. include_str!("builtins/shortcodes/vimeo.html"),
  45. ),
  46. ("__zola_builtins/shortcodes/gist.html", include_str!("builtins/shortcodes/gist.html")),
  47. (
  48. "__zola_builtins/shortcodes/streamable.html",
  49. include_str!("builtins/shortcodes/streamable.html"),
  50. ),
  51. ("internal/alias.html", include_str!("builtins/internal/alias.html")),
  52. ])
  53. .unwrap();
  54. tera.register_filter("markdown", filters::markdown);
  55. tera.register_filter("base64_encode", filters::base64_encode);
  56. tera.register_filter("base64_decode", filters::base64_decode);
  57. tera
  58. };
  59. }
  60. /// Renders the `internal/alias.html` template that will redirect
  61. /// via refresh to the url given
  62. pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
  63. let mut context = Context::new();
  64. context.insert("url", &url);
  65. tera.render("internal/alias.html", context)
  66. .map_err(|e| Error::chain(format!("Failed to render alias for '{}'", url), e))
  67. }