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.

169 lines
4.8KB

  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. [extra.author]
  87. name = "Vincent Prouillet"
  88. """)
  89. else:
  90. f.write("""
  91. title = "My site"
  92. base_url = "https://replace-this-with-your-url.com"
  93. [extra.author]
  94. name = "Vincent Prouillet"
  95. """)
  96. # Re-use the test templates
  97. shutil.copytree("../test_site/templates", os.path.join(name, "templates"))
  98. def gen_section(path, num_pages, is_blog):
  99. with open(os.path.join(path, "_index.md"), "w") as f:
  100. if is_blog:
  101. f.write("""
  102. +++
  103. paginate_by = 5
  104. sort_by = "date"
  105. template = "section_paginated.html"
  106. +++
  107. """)
  108. else:
  109. f.write("+++\n+++\n")
  110. day = datetime.date.today()
  111. for (i, page) in enumerate(range(0, num_pages)):
  112. with open(os.path.join(path, "page-{}.md".format(i)), "w") as f:
  113. f.write(
  114. PAGE
  115. .replace("REPLACE_DATE", str(day + datetime.timedelta(days=1)))
  116. .replace("REPLACE_CATEGORY", random.choice(CATEGORIES))
  117. .replace("REPLACE_TAG", str([random.choice(TAGS), random.choice(TAGS)]))
  118. )
  119. def gen_site(name, sections, num_pages_per_section, is_blog=False):
  120. gen_skeleton(name, is_blog)
  121. for section in sections:
  122. path = os.path.join(name, "content", section) if section else os.path.join(name, "content")
  123. if section:
  124. os.makedirs(path)
  125. gen_section(path, num_pages_per_section, is_blog)
  126. if __name__ == "__main__":
  127. gen_site("small-blog", [""], 30, is_blog=True)
  128. gen_site("medium-blog", [""], 250, is_blog=True)
  129. gen_site("big-blog", [""], 1000, is_blog=True)
  130. gen_site("huge-blog", [""], 10000, is_blog=True)
  131. gen_site("small-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 10)
  132. gen_site("medium-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 100)
  133. gen_site("huge-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 1000)