Skip to content

Commit 5aaab20

Browse files
committed
Add toc tree generation
1 parent 6909cb5 commit 5aaab20

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

.ci/generate_operators_doc.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
from pathlib import Path
3-
import shutil
3+
import json
4+
import os
45

56
from jinja2 import Template
67

@@ -146,6 +147,34 @@ def generate_operator_doc(server, operator_name, include_private):
146147
with Path.open(Path(file_dir) / f"{file_name}.md", "w") as file:
147148
file.write(output)
148149

150+
def generate_toc_tree(docs_path):
151+
data = []
152+
for folder in docs_path.iterdir():
153+
if folder.is_dir(): # Ensure 'folder' is a directory
154+
category = folder.name
155+
operators = [] # Reset operators for each category
156+
for file in folder.iterdir():
157+
if file.is_file() and file.suffix == ".md": # Ensure 'file' is a file with .md extension
158+
file_name = file.name
159+
operator_name = file_name.replace("_", " ").replace(".md", "")
160+
operators.append({"operator_name": operator_name, "file_name": file_name})
161+
data.append({"category": category, "operators": operators})
162+
163+
# Write the JSON file for debugging purposes
164+
with open(docs_path / "toc_tree.json", "w") as file:
165+
json.dump(data, file, indent=4)
166+
167+
# Render the Jinja2 template
168+
template_path = docs_path / "toc_template.j2"
169+
with open(template_path, "r") as template_file:
170+
template = Template(template_file.read())
171+
output = template.render(data=data) # Pass 'data' as a named argument
172+
173+
# Write the rendered output to toc.md
174+
with open(docs_path / "toc.md", "w") as file:
175+
file.write(output)
176+
177+
149178

150179
def main():
151180
parser = argparse.ArgumentParser(description="Fetch available operators")
@@ -169,6 +198,10 @@ def main():
169198
for operator_name in operators:
170199
generate_operator_doc(server, operator_name, args.include_private)
171200

201+
docs_path = Path(__file__).parent.parent / "doc" / "source" / "operators_doc"
202+
print(docs_path)
203+
generate_toc_tree(docs_path)
204+
172205

173206
if __name__ == "__main__":
174207
main()

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ doc/_build/
7272
# Operators documentation
7373
doc/source/operators_doc/**/*
7474
!doc/source/operators_doc/operator_doc_template.md
75+
!doc/source/operators_doc/toc_template.j2
7576

7677
# PyBuilder
7778
.pybuilder/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- name: Introduction
2+
href: index.md
3+
{% for category in data %}
4+
- name: {{ category.category }}
5+
items:{% for operator in category.operators %}
6+
- name: {{ operator.operator_name }}
7+
href: {{ operator.file_name }}{% endfor %}
8+
{% endfor %}

0 commit comments

Comments
 (0)