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.

all.rs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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::{RenderContext, render_content, 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_render_content_with_highlighting(b: &mut test::Bencher) {
  71. let mut tera = Tera::default();
  72. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  73. let permalinks_ctx = HashMap::new();
  74. let config = Config::default();
  75. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  76. b.iter(|| render_content(CONTENT, &context).unwrap());
  77. }
  78. #[bench]
  79. fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
  80. let mut tera = Tera::default();
  81. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  82. let permalinks_ctx = HashMap::new();
  83. let mut config = Config::default();
  84. config.highlight_code = false;
  85. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  86. b.iter(|| render_content(CONTENT, &context).unwrap());
  87. }
  88. #[bench]
  89. fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
  90. let tera = Tera::default();
  91. let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
  92. let mut config = Config::default();
  93. config.highlight_code = false;
  94. let permalinks_ctx = HashMap::new();
  95. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  96. b.iter(|| render_content(&content2, &context).unwrap());
  97. }
  98. #[bench]
  99. fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
  100. let mut tera = Tera::default();
  101. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  102. b.iter(|| render_shortcodes(CONTENT, &tera, &Config::default()));
  103. }