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.

146 lines
4.2KB

  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 shutil
  8. PAGE = """
  9. +++
  10. title = "Hello"
  11. date = "REPLACE_ME"
  12. +++
  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. def gen_skeleton(name):
  70. if os.path.exists(name):
  71. shutil.rmtree(name)
  72. os.makedirs(os.path.join(name, "content"))
  73. os.makedirs(os.path.join(name, "static"))
  74. with open(os.path.join(name, "config.toml"), "w") as f:
  75. f.write("""
  76. title = "My site"
  77. base_url = "https://replace-this-with-your-url.com"
  78. [extra.author]
  79. name = "Vincent Prouillet"
  80. """)
  81. # Re-use the test templates
  82. shutil.copytree("../test_site/templates", os.path.join(name, "templates"))
  83. def gen_section(path, num_pages, paginate):
  84. with open(os.path.join(path, "_index.md"), "w") as f:
  85. if paginate:
  86. f.write("""
  87. +++
  88. paginate_by = 5
  89. sort_by = "date"
  90. template = "section_paginated.html"
  91. +++
  92. """)
  93. else:
  94. f.write("+++\n+++\n")
  95. day = datetime.date.today()
  96. for (i, page) in enumerate(range(0, num_pages)):
  97. with open(os.path.join(path, "page-{}.md".format(i)), "w") as f:
  98. f.write(PAGE.replace("REPLACE_ME", str(day + datetime.timedelta(days=1))))
  99. def gen_site(name, sections, num_pages_per_section, paginate=False):
  100. gen_skeleton(name)
  101. for section in sections:
  102. path = os.path.join(name, "content", section) if section else os.path.join(name, "content")
  103. if section:
  104. os.makedirs(path)
  105. gen_section(path, num_pages_per_section, paginate)
  106. if __name__ == "__main__":
  107. gen_site("small-blog", [""], 30, paginate=True)
  108. gen_site("medium-blog", [""], 250, paginate=True)
  109. gen_site("big-blog", [""], 1000, paginate=True)
  110. gen_site("huge-blog", [""], 10000, paginate=True)
  111. gen_site("small-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 10)
  112. gen_site("medium-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 100)
  113. gen_site("huge-kb", ["help", "help1", "help2", "help3", "help4", "help5", "help6", "help7", "help8", "help9"], 1000)