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.

171 lines
4.9KB

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