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.

42 lines
1.1KB

  1. use std::collections::HashMap;
  2. use tera::Tera;
  3. use config::Config;
  4. use front_matter::InsertAnchor;
  5. /// All the information from the gutenberg site that is needed to render HTML from markdown
  6. #[derive(Debug)]
  7. pub struct Context<'a> {
  8. pub tera: &'a Tera,
  9. pub highlight_code: bool,
  10. pub highlight_theme: String,
  11. pub current_page_permalink: String,
  12. pub permalinks: &'a HashMap<String, String>,
  13. pub insert_anchor: InsertAnchor,
  14. }
  15. impl<'a> Context<'a> {
  16. pub fn new(
  17. tera: &'a Tera,
  18. config: &'a Config,
  19. current_page_permalink: &str,
  20. permalinks: &'a HashMap<String, String>,
  21. insert_anchor: InsertAnchor,
  22. ) -> Context<'a> {
  23. Context {
  24. tera,
  25. current_page_permalink: current_page_permalink.to_string(),
  26. permalinks,
  27. insert_anchor,
  28. highlight_code: config.highlight_code.unwrap(),
  29. highlight_theme: config.highlight_theme.clone().unwrap(),
  30. }
  31. }
  32. pub fn should_insert_anchor(&self) -> bool {
  33. self.insert_anchor != InsertAnchor::None
  34. }
  35. }