1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/env python3
import pathlib
import re
import sys
ROOT_DIR = pathlib.Path(__file__).parent.parent
README = ROOT_DIR / "README.md"
INDEX = ROOT_DIR / "docs" / "index.md"
QUICKSTART = ROOT_DIR / "examples" / "quickstart.py"
USED_FILES = {str(path.relative_to(ROOT_DIR)) for path in (INDEX, QUICKSTART)}
def main():
content = INDEX.read_text()
# Set title
content = re.sub(r"# Overview\s*## apischema", "# apischema", content)
# Remove FAQ
content = content[: content.index("## FAQ")]
# Remove admonitions
content = re.sub(r"!!! note\n\s*(.*)\n", lambda m: f"> {m.group(1)}\n", content)
# Add chart
# TODO remove this unused part?
content = content.replace(
r"<!--insert chart-->",
"\n".join(
""
for theme in ("light", "dark")
),
)
# Uncomment
content = re.sub(r"<!--\n(\s*(.|\n)*?\s*)\n-->", lambda m: m.group(1), content)
# TODO remove this unused part?
content = re.sub(
r"(\d+\.\d+)/benchmark_chart\.svg", "dev/benchmark_chart.svg", content
)
# Rewrite links
content = re.sub(
r"\(([\w/]+)\.(md|svg)(#[\w-]+)?\)",
lambda m: f"(https://wyfo.github.io/apischema/dev/{m.group(1)}"
+ (".svg" if m.group(2) == "svg" else "")
+ (m.group(3) or "")
+ ")",
content,
)
# Add quickstart
content = re.sub(
"```python(.|\n)*?```", f"```python\n{QUICKSTART.read_text()}```", content
)
README.write_text(content)
if __name__ == "__main__":
if not set(sys.argv).isdisjoint(USED_FILES):
main()
|