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.

120 lines
3.6KB

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