Skip to content

Commit 34a5ede

Browse files
committed
feat(documentation): Add indexes to operator categories in operator documentation sources
1 parent 1362534 commit 34a5ede

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/ansys/dpf/core/documentation/generate_operators_doc.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def generate_operator_doc(
348348
"""
349349
operator_info = fetch_doc_info(server, operator_name)
350350
scripting_name = operator_info["scripting_info"]["scripting_name"]
351-
category = operator_info["scripting_info"]["category"]
351+
category: str = operator_info["scripting_info"]["category"]
352352
if scripting_name:
353353
file_name = scripting_name
354354
else:
@@ -391,7 +391,10 @@ def update_toc_tree(docs_path: Path):
391391
operators = [] # Reset operators for each category
392392
for file in folder.iterdir():
393393
if (
394-
file.is_file() and file.suffix == ".md" and not file.name.endswith("_upd.md")
394+
file.is_file()
395+
and file.suffix == ".md"
396+
and not file.name.endswith("_upd.md")
397+
and not file.name.endswith("_category.md")
395398
): # Ensure 'file' is a file with .md extension
396399
file_name = file.name
397400
file_path = f"{category}/{file_name}"
@@ -419,6 +422,60 @@ def update_toc_tree(docs_path: Path):
419422
file.write(new_toc)
420423

421424

425+
def update_categories(docs_path: Path):
426+
"""Update the category index files for the operator specifications.
427+
428+
Parameters
429+
----------
430+
docs_path:
431+
Path to the root of the DPF documentation sources.
432+
433+
"""
434+
specs_path = docs_path / Path("operator-specifications")
435+
for folder in specs_path.iterdir():
436+
if folder.is_dir(): # Ensure 'folder' is a directory
437+
category = folder.name
438+
operators = [] # Reset operators for each category
439+
for file in folder.iterdir():
440+
if (
441+
file.is_file()
442+
and file.suffix == ".md"
443+
and not file.name.endswith("_upd.md")
444+
and not file.name.endswith("_category.md")
445+
): # Ensure 'file' is a file with .md extension
446+
file_name = file.name
447+
operator_name = file_name.replace("_", " ").replace(".md", "")
448+
operators.append({"operator_name": operator_name, "file_path": file_name})
449+
# Update category index file
450+
category_file_path = folder / f"{category}_category.md"
451+
with category_file_path.open(mode="w") as cat_file:
452+
cat_file.write(f"# {category.capitalize()} operators\n\n")
453+
for operator in operators:
454+
cat_file.write(f"- [{operator['operator_name']}]({operator['file_path']})\n")
455+
456+
457+
def update_operator_index(docs_path: Path):
458+
"""Update the main index file for all operator specifications.
459+
460+
Parameters
461+
----------
462+
docs_path:
463+
Path to the root of the DPF documentation sources.
464+
465+
"""
466+
specs_path = docs_path / Path("operator-specifications")
467+
index_file_path = specs_path / "operator-specifications.md"
468+
with index_file_path.open(mode="w") as index_file:
469+
index_file.write("# Operator Specifications\n\n")
470+
for folder in specs_path.iterdir():
471+
if folder.is_dir(): # Ensure 'folder' is a directory
472+
category = folder.name
473+
index_file.write(
474+
f"## [{category.capitalize()} operators]({category}/{category}_category.md)\n\n"
475+
)
476+
index_file.write("\n")
477+
478+
422479
def generate_operators_doc(
423480
output_path: Path,
424481
ansys_path: Path = None,
@@ -461,6 +518,10 @@ def generate_operators_doc(
461518
generate_operator_doc(server, operator_name, include_private, output_path)
462519
# Generate the toc tree
463520
update_toc_tree(output_path)
521+
# Generate the category index files
522+
update_categories(output_path)
523+
# Generate the main index file for all categories
524+
update_operator_index(output_path)
464525
# Use update files in output_path
465526
update_operator_descriptions(output_path)
466527

src/ansys/dpf/core/documentation/toc_template.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
href: operator-specifications/operator-specifications.md
55
{% for category in data -%}
66
- name: {{ category.category }}
7+
href: operator-specifications/{{ category.category }}/{{ category.category }}_category.md
78
items:{% for operator in category.operators %}
89
- name: {{ operator.operator_name }}
910
href: operator-specifications/{{ operator.file_path }}{% endfor %}

0 commit comments

Comments
 (0)