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.

177 lines
5.0KB

  1. """
  2. Generates test sites for use in benchmark.
  3. Tested with python3 and probably does not work on Windows.
  4. """
  5. import datetime
  6. import os
  7. import random
  8. import shutil
  9. TAGS = ["a", "b", "c", "d", "e", "f", "g"]
  10. CATEGORIES = ["c1", "c2", "c3", "c4"]
  11. PAGE = """
  12. +++
  13. title = "Hello"
  14. date = REPLACE_DATE
  15. [taxonomies]
  16. tags = REPLACE_TAG
  17. categories = ["REPLACE_CATEGORY"]
  18. +++
  19. # Modus cognitius profanam ne duae virtutis mundi
  20. ## Ut vita
  21. Lorem markdownum litora, care ponto nomina, et ut aspicit gelidas sui et
  22. purpureo genuit. Tamen colla venientis [delphina](http://nil-sol.com/ecquis)
  23. Tusci et temptata citaeque curam isto ubi vult vulnere reppulit.
  24. - Seque vidit flendoque de quodam
  25. - Dabit minimos deiecto caputque noctis pluma
  26. - Leti coniunx est Helicen
  27. - Illius pulvereumque Icare inpositos
  28. - Vivunt pereo pluvio tot ramos Olenios gelidis
  29. - Quater teretes natura inde
  30. ### A subsection
  31. Protinus dicunt, breve per, et vivacis genus Orphei munere. Me terram [dimittere
  32. casside](http://corpus.org/) pervenit saxo primoque frequentat genuum sorori
  33. praeferre causas Libys. Illud in serpit adsuetam utrimque nunc haberent,
  34. **terrae si** veni! Hectoreis potes sumite [Mavortis retusa](http://tua.org/)
  35. granum captantur potuisse Minervae, frugum.
  36. > Clivo sub inprovisoque nostrum minus fama est, discordia patrem petebat precatur
  37. absumitur, poena per sit. Foramina *tamen cupidine* memor supplex tollentes
  38. dictum unam orbem, Anubis caecae. Viderat formosior tegebat satis, Aethiopasque
  39. sit submisso coniuge tristis ubi!
  40. ## Praeceps Corinthus totidem quem crus vultum cape
  41. ```rs
  42. #[derive(Debug)]
  43. pub struct Site {
  44. /// The base path of the zola site
  45. pub base_path: PathBuf,
  46. /// The parsed config for the site
  47. pub config: Config,
  48. pub pages: HashMap<PathBuf, Page>,
  49. pub sections: HashMap<PathBuf, Section>,
  50. pub tera: Tera,
  51. live_reload: bool,
  52. output_path: PathBuf,
  53. static_path: PathBuf,
  54. pub tags: Option<Taxonomy>,
  55. pub categories: Option<Taxonomy>,
  56. /// A map of all .md files (section and pages) and their permalink
  57. /// We need that if there are relative links in the content that need to be resolved
  58. pub permalinks: HashMap<String, String>,
  59. }
  60. ```
  61. ## More stuff
  62. And a shortcode:
  63. {{ youtube(id="my_youtube_id") }}
  64. ### Another subsection
  65. Gotta make the toc do a little bit of work
  66. # A big title
  67. - hello
  68. - world
  69. - !
  70. ```py
  71. if __name__ == "__main__":
  72. gen_site("basic-blog", [""], 250, paginate=True)
  73. ```
  74. """
  75. def gen_skeleton(name, is_blog):
  76. if os.path.exists(name):
  77. shutil.rmtree(name)
  78. os.makedirs(os.path.join(name, "content"))
  79. os.makedirs(os.path.join(name, "static"))
  80. with open(os.path.join(name, "config.toml"), "w") as f:
  81. if is_blog:
  82. f.write("""
  83. title = "My site"
  84. base_url = "https://replace-this-with-your-url.com"
  85. theme = "sample"
  86. taxonomies = [
  87. {name = "tags", rss = true},
  88. {name = "categories"}
  89. ]
  90. [extra.author]
  91. name = "Vincent Prouillet"
  92. """)
  93. else:
  94. f.write("""
  95. title = "My site"
  96. base_url = "https://replace-this-with-your-url.com"
  97. theme = "sample"
  98. [extra.author]
  99. name = "Vincent Prouillet"
  100. """)
  101. # Re-use the test templates
  102. shutil.copytree("../../../test_site/templates", os.path.join(name, "templates"))
  103. shutil.copytree("../../../test_site/themes", os.path.join(name, "themes"))
  104. def gen_section(path, num_pages, is_blog):
  105. with open(os.path.join(path, "_index.md"), "w") as f:
  106. if is_blog:
  107. f.write("""
  108. +++
  109. paginate_by = 5
  110. sort_by = "date"
  111. template = "section_paginated.html"
  112. +++
  113. """)
  114. else:
  115. f.write("+++\n+++\n")
  116. day = datetime.date.today()
  117. for (i, page) in enumerate(range(0, num_pages)):
  118. with open(os.path.join(path, "page-{}.md".format(i)), "w") as f:
  119. f.write(
  120. PAGE
  121. .replace("REPLACE_DATE", str(day + datetime.timedelta(days=1)))
  122. .replace("REPLACE_CATEGORY", random.choice(CATEGORIES))
  123. .replace("REPLACE_TAG", str([random.choice(TAGS), random.choice(TAGS)]))
  124. )
  125. def gen_site(name, sections, num_pages_per_section, is_blog=False):
  126. gen_skeleton(name, is_blog)
  127. for section in sections:
  128. path = os.path.join(name, "content", section) if section else os.path.join(name, "content")
  129. if section:
  130. os.makedirs(path)
  131. gen_section(path, num_pages_per_section, is_blog)
  132. if __name__ == "__main__":
  133. gen_site("small-blog", [""], 30, is_blog=True)
  134. gen_site("medium-blog", [""], 250, is_blog=True)
  135. gen_site("big-blog", [""], 1000, is_blog=True)
  136. gen_site("huge-blog", [""], 10000, is_blog=True)
  137. gen_site("extra-huge-blog", [""], 100000, is_blog=True)
  138. gen_site("small-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 10)
  139. gen_site("medium-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 100)
  140. gen_site("huge-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 1000)