2023-11-10 07:36:21 +00:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
2024-05-02 00:34:05 +00:00
|
|
|
import sys
|
2023-11-14 22:17:44 +00:00
|
|
|
from pathlib import Path
|
2023-11-10 07:36:21 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
intermediate_dir = Path(sys.argv[1])
|
2023-11-10 07:36:21 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
templates_source_dir = Path(os.path.abspath(__file__)).parents[2] / "templates"
|
|
|
|
templates_intermediate_dir = intermediate_dir / "templates"
|
2023-11-10 07:36:21 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
readmes = list(glob.glob(str(templates_source_dir) + "/*/README.md"))
|
|
|
|
destinations = [
|
|
|
|
readme[len(str(templates_source_dir)) + 1 : -10] + ".md" for readme in readmes
|
|
|
|
]
|
|
|
|
for source, destination in zip(readmes, destinations):
|
|
|
|
full_destination = templates_intermediate_dir / destination
|
|
|
|
shutil.copyfile(source, full_destination)
|
|
|
|
with open(full_destination, "r") as f:
|
|
|
|
content = f.read()
|
|
|
|
# remove images
|
2024-05-17 22:59:27 +00:00
|
|
|
content = re.sub(r"\!\[.*?\]\((.*?)\)", "", content)
|
2024-05-02 00:34:05 +00:00
|
|
|
with open(full_destination, "w") as f:
|
|
|
|
f.write(content)
|
2023-11-10 07:36:21 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
sidebar_hidden = """---
|
2023-11-10 07:36:21 +00:00
|
|
|
sidebar_class_name: hidden
|
2024-05-24 19:44:46 +00:00
|
|
|
custom_edit_url:
|
2023-11-10 07:36:21 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
"""
|
2024-03-11 17:50:39 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
# handle index file
|
|
|
|
templates_index_source = templates_source_dir / "docs" / "INDEX.md"
|
|
|
|
templates_index_intermediate = templates_intermediate_dir / "index.md"
|
|
|
|
|
|
|
|
with open(templates_index_source, "r") as f:
|
|
|
|
content = f.read()
|
|
|
|
|
|
|
|
# replace relative links
|
2024-05-17 22:59:27 +00:00
|
|
|
content = re.sub(r"\]\(\.\.\/", "](/docs/templates/", content)
|
2024-03-11 17:50:39 +00:00
|
|
|
|
2024-05-02 00:34:05 +00:00
|
|
|
with open(templates_index_intermediate, "w") as f:
|
|
|
|
f.write(sidebar_hidden + content)
|