mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-10-14 03:43:45 +00:00
Enhance export_docs.py with Table of Contents feature (#865)
* Enhance export_docs.py with Table of Contents feature Added a Table of Contents generation feature to the documentation export script, enhancing navigation through consolidated markdown files. * fix: remove duplicated orphaned code from export_docs.py The TOC change accidentally duplicated consolidate_folder/main and left the old body orphaned after the __main__ guard, causing an IndentationError. Keep only the intended TOC generation so the script runs again. --------- Co-authored-by: Luis Novo <lfnovo@gmail.com>
This commit is contained in:
parent
0aaaa32455
commit
238e8e925d
1 changed files with 17 additions and 5 deletions
|
|
@ -5,7 +5,8 @@ Export documentation by consolidating markdown files from each docs folder.
|
||||||
This script:
|
This script:
|
||||||
1. Scans all subdirectories in the docs/ folder
|
1. Scans all subdirectories in the docs/ folder
|
||||||
2. For each subdirectory, concatenates all .md files (except index.md)
|
2. For each subdirectory, concatenates all .md files (except index.md)
|
||||||
3. Saves the consolidated content to doc_exports/{folder_name}.md
|
3. Generates a Table of Contents for easy navigation
|
||||||
|
4. Saves the consolidated content to doc_exports/{folder_name}.md
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -24,7 +25,7 @@ def get_markdown_files(folder: Path) -> List[Path]:
|
||||||
|
|
||||||
|
|
||||||
def consolidate_folder(folder: Path, output_dir: Path) -> None:
|
def consolidate_folder(folder: Path, output_dir: Path) -> None:
|
||||||
"""Consolidate all markdown files from a folder into a single file."""
|
"""Consolidate all markdown files from a folder into a single file with a TOC."""
|
||||||
md_files = get_markdown_files(folder)
|
md_files = get_markdown_files(folder)
|
||||||
|
|
||||||
if not md_files:
|
if not md_files:
|
||||||
|
|
@ -35,11 +36,22 @@ def consolidate_folder(folder: Path, output_dir: Path) -> None:
|
||||||
|
|
||||||
with output_file.open("w", encoding="utf-8") as outf:
|
with output_file.open("w", encoding="utf-8") as outf:
|
||||||
# Write header
|
# Write header
|
||||||
outf.write(f"# {folder.name.replace('-', ' ').title()}\n\n")
|
folder_title = folder.name.replace("-", " ").title()
|
||||||
|
outf.write(f"# {folder_title}\n\n")
|
||||||
outf.write(
|
outf.write(
|
||||||
f"This document consolidates all content from the {folder.name} documentation folder.\n\n"
|
f"This document consolidates all content from the {folder.name} documentation folder.\n\n"
|
||||||
)
|
)
|
||||||
outf.write("---\n\n")
|
|
||||||
|
# Generate a Table of Contents dynamically
|
||||||
|
outf.write("## Table of Contents\n\n")
|
||||||
|
for md_file in md_files:
|
||||||
|
section_title = md_file.stem.replace("-", " ").title()
|
||||||
|
# Convert title to a markdown-friendly anchor link
|
||||||
|
# (lowercase, hyphens instead of spaces)
|
||||||
|
anchor = section_title.lower().replace(" ", "-")
|
||||||
|
outf.write(f"* [{section_title}](#{anchor})\n")
|
||||||
|
|
||||||
|
outf.write("\n---\n\n")
|
||||||
|
|
||||||
# Process each markdown file
|
# Process each markdown file
|
||||||
for md_file in md_files:
|
for md_file in md_files:
|
||||||
|
|
@ -88,7 +100,7 @@ def main():
|
||||||
logger.info(f"Processing {subdir.name}...")
|
logger.info(f"Processing {subdir.name}...")
|
||||||
consolidate_folder(subdir, output_dir)
|
consolidate_folder(subdir, output_dir)
|
||||||
|
|
||||||
logger.info(f"\n✓ Documentation export complete!")
|
logger.info("\n✓ Documentation export complete!")
|
||||||
logger.info(f"Exported files are in: {output_dir.absolute()}")
|
logger.info(f"Exported files are in: {output_dir.absolute()}")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue