2023-11-10 07:36:21 +00:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
2023-11-14 22:17:44 +00:00
|
|
|
from pathlib import Path
|
2023-11-10 07:36:21 +00:00
|
|
|
|
|
|
|
TEMPLATES_DIR = Path(os.path.abspath(__file__)).parents[2] / "templates"
|
|
|
|
DOCS_TEMPLATES_DIR = Path(os.path.abspath(__file__)).parents[1] / "docs" / "templates"
|
|
|
|
|
|
|
|
|
|
|
|
readmes = list(glob.glob(str(TEMPLATES_DIR) + "/*/README.md"))
|
2023-11-14 20:58:22 +00:00
|
|
|
destinations = [readme[len(str(TEMPLATES_DIR)) + 1 : -10] + ".md" for readme in readmes]
|
2023-11-10 07:36:21 +00:00
|
|
|
for source, destination in zip(readmes, destinations):
|
|
|
|
full_destination = DOCS_TEMPLATES_DIR / destination
|
|
|
|
shutil.copyfile(source, full_destination)
|
|
|
|
with open(full_destination, "r") as f:
|
|
|
|
content = f.read()
|
|
|
|
# remove images
|
|
|
|
content = re.sub("\!\[.*?\]\((.*?)\)", "", content)
|
|
|
|
with open(full_destination, "w") as f:
|
|
|
|
f.write(content)
|
|
|
|
|
|
|
|
sidebar_hidden = """---
|
|
|
|
sidebar_class_name: hidden
|
|
|
|
---
|
|
|
|
|
|
|
|
"""
|
|
|
|
TEMPLATES_INDEX_DESTINATION = DOCS_TEMPLATES_DIR / "index.md"
|
|
|
|
with open(TEMPLATES_INDEX_DESTINATION, "r") as f:
|
|
|
|
content = f.read()
|
2024-03-11 17:50:39 +00:00
|
|
|
|
2023-11-10 07:36:21 +00:00
|
|
|
# replace relative links
|
|
|
|
content = re.sub("\]\(\.\.\/", "](/docs/templates/", content)
|
2024-03-11 17:50:39 +00:00
|
|
|
|
2023-11-10 07:36:21 +00:00
|
|
|
with open(TEMPLATES_INDEX_DESTINATION, "w") as f:
|
|
|
|
f.write(sidebar_hidden + content)
|