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.

128 lines
4.1KB

  1. use std::collections::HashMap;
  2. use std::path::Path;
  3. use config::Config;
  4. use front_matter::InsertAnchor;
  5. use rendering::{render_content, render_shortcodes, RenderContext};
  6. use tera::Tera;
  7. static CONTENT: &'static str = r#"
  8. # Modus cognitius profanam ne duae virtutis mundi
  9. ## Ut vita
  10. Lorem markdownum litora, care ponto nomina, et ut aspicit gelidas sui et
  11. purpureo genuit. Tamen colla venientis [delphina](http://nil-sol.com/ecquis)
  12. Tusci et temptata citaeque curam isto ubi vult vulnere reppulit.
  13. - Seque vidit flendoque de quodam
  14. - Dabit minimos deiecto caputque noctis pluma
  15. - Leti coniunx est Helicen
  16. - Illius pulvereumque Icare inpositos
  17. - Vivunt pereo pluvio tot ramos Olenios gelidis
  18. - Quater teretes natura inde
  19. ### A subsection
  20. Protinus dicunt, breve per, et vivacis genus Orphei munere. Me terram [dimittere
  21. casside](http://corpus.org/) pervenit saxo primoque frequentat genuum sorori
  22. praeferre causas Libys. Illud in serpit adsuetam utrimque nunc haberent,
  23. **terrae si** veni! Hectoreis potes sumite [Mavortis retusa](http://tua.org/)
  24. granum captantur potuisse Minervae, frugum.
  25. > Clivo sub inprovisoque nostrum minus fama est, discordia patrem petebat precatur
  26. absumitur, poena per sit. Foramina *tamen cupidine* memor supplex tollentes
  27. dictum unam orbem, Anubis caecae. Viderat formosior tegebat satis, Aethiopasque
  28. sit submisso coniuge tristis ubi!
  29. ## Praeceps Corinthus totidem quem crus vultum cape
  30. ```rs
  31. #[derive(Debug)]
  32. pub struct Site {
  33. /// The base path of the gutenberg site
  34. pub base_path: PathBuf,
  35. /// The parsed config for the site
  36. pub config: Config,
  37. pub pages: HashMap<PathBuf, Page>,
  38. pub sections: HashMap<PathBuf, Section>,
  39. pub tera: Tera,
  40. live_reload: bool,
  41. output_path: PathBuf,
  42. static_path: PathBuf,
  43. pub tags: Option<Taxonomy>,
  44. pub categories: Option<Taxonomy>,
  45. /// A map of all .md files (section and pages) and their permalink
  46. /// We need that if there are relative links in the content that need to be resolved
  47. pub permalinks: HashMap<String, String>,
  48. }
  49. ```
  50. ## More stuff
  51. And a shortcode:
  52. {{ youtube(id="my_youtube_id") }}
  53. ### Another subsection
  54. Gotta make the toc do a little bit of work
  55. # A big title
  56. - hello
  57. - world
  58. - !
  59. ```py
  60. if __name__ == "__main__":
  61. gen_site("basic-blog", [""], 250, paginate=True)
  62. ```
  63. "#;
  64. #[bench]
  65. fn bench_render_content_with_highlighting(b: &mut test::Bencher) {
  66. let mut tera = Tera::default();
  67. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  68. let permalinks_ctx = HashMap::new();
  69. let config = Config::default();
  70. let context =
  71. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  72. b.iter(|| render_content(CONTENT, &context).unwrap());
  73. }
  74. #[bench]
  75. fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
  76. let mut tera = Tera::default();
  77. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  78. let permalinks_ctx = HashMap::new();
  79. let mut config = Config::default();
  80. config.highlight_code = false;
  81. let context =
  82. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  83. b.iter(|| render_content(CONTENT, &context).unwrap());
  84. }
  85. #[bench]
  86. fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
  87. let tera = Tera::default();
  88. let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
  89. let mut config = Config::default();
  90. config.highlight_code = false;
  91. let permalinks_ctx = HashMap::new();
  92. let context =
  93. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  94. b.iter(|| render_content(&content2, &context).unwrap());
  95. }
  96. #[bench]
  97. fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
  98. let mut tera = Tera::default();
  99. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  100. let config = Config::default();
  101. let permalinks_ctx = HashMap::new();
  102. let context =
  103. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  104. b.iter(|| render_shortcodes(CONTENT, &context));
  105. }