datahub/docs-website/sphinx/convert_sphinx_to_docusaurus.py

40 lines
1.2 KiB
Python
Raw Normal View History

import pathlib
SPHINX_ROOT_DIR = pathlib.Path(".")
2025-06-09 18:50:31 +09:00
SPHINX_BUILD_DIR = SPHINX_ROOT_DIR / pathlib.Path("_build/markdown/apidocs")
DOCS_OUTPUT_DIR = pathlib.Path("../docs/python-sdk")
2025-06-09 18:50:31 +09:00
def main():
DOCS_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
2025-06-09 18:50:31 +09:00
for doc in SPHINX_BUILD_DIR.glob("**/*.md"):
outfile = DOCS_OUTPUT_DIR / doc.relative_to(SPHINX_BUILD_DIR)
outfile.parent.mkdir(parents=True, exist_ok=True)
2025-06-09 18:50:31 +09:00
with open(doc, "r") as f:
content = f.read()
2025-06-09 18:50:31 +09:00
# Replace dangerous characters
replacements = [
("<function ", "<\\function "),
("<id>", "<\\id>"),
("<type>", "<\\type>"),
("<id1>", "<\\id1>"),
("<id2>", "<\\id2>"),
("MDXContent.isMDXComponent = true", ""),
]
for old, new in replacements:
content = content.replace(old, new)
2025-06-09 18:50:31 +09:00
# Wrap the entire content with div (top and bottom)
final_content = f"<div className=\"python-sdk\">\n\n{content.strip()}\n\n</div>\n"
2025-06-09 18:50:31 +09:00
with open(outfile, "w") as f:
f.write(final_content)
2025-06-09 18:50:31 +09:00
print(f"✅ Generated {outfile}")
if __name__ == "__main__":
main()