File size: 3,005 Bytes
f871fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
Export documentation by consolidating markdown files from each docs folder.

This script:
1. Scans all subdirectories in the docs/ folder
2. For each subdirectory, concatenates all .md files (except index.md)
3. Saves the consolidated content to doc_exports/{folder_name}.md
"""

import logging
from pathlib import Path
from typing import List

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
logger = logging.getLogger(__name__)


def get_markdown_files(folder: Path) -> List[Path]:
    """Get all markdown files in a folder, excluding index.md files."""
    md_files = [f for f in folder.glob("*.md") if f.name.lower() != "index.md"]
    return sorted(md_files)  # Sort for consistent ordering


def consolidate_folder(folder: Path, output_dir: Path) -> None:
    """Consolidate all markdown files from a folder into a single file."""
    md_files = get_markdown_files(folder)

    if not md_files:
        logger.info(f"  Skipping {folder.name} - no markdown files found")
        return

    output_file = output_dir / f"{folder.name}.md"

    with output_file.open("w", encoding="utf-8") as outf:
        # Write header
        outf.write(f"# {folder.name.replace('-', ' ').title()}\n\n")
        outf.write(f"This document consolidates all content from the {folder.name} documentation folder.\n\n")
        outf.write("---\n\n")

        # Process each markdown file
        for md_file in md_files:
            logger.info(f"  Adding {md_file.name}")

            # Add section header with filename
            outf.write(f"## {md_file.stem.replace('-', ' ').title()}\n\n")
            outf.write(f"*Source: {md_file.name}*\n\n")

            # Add file content
            content = md_file.read_text(encoding="utf-8")
            outf.write(content)
            outf.write("\n\n---\n\n")

    logger.info(f"  ✓ Created {output_file.name} ({len(md_files)} files)")


def main():
    """Main function to export documentation."""
    # Define paths
    docs_dir = Path("docs")
    output_dir = Path("doc_exports")

    # Validate docs directory exists
    if not docs_dir.exists():
        logger.error(f"Documentation directory '{docs_dir}' not found")
        return

    # Create output directory
    output_dir.mkdir(exist_ok=True)
    logger.info(f"Output directory: {output_dir.absolute()}")

    # Get all subdirectories in docs/
    subdirs = [d for d in docs_dir.iterdir() if d.is_dir() and not d.name.startswith(".")]

    if not subdirs:
        logger.warning("No subdirectories found in docs/")
        return

    logger.info(f"Found {len(subdirs)} documentation folders\n")

    # Process each subdirectory
    for subdir in sorted(subdirs):
        logger.info(f"Processing {subdir.name}...")
        consolidate_folder(subdir, output_dir)

    logger.info(f"\n✓ Documentation export complete!")
    logger.info(f"Exported files are in: {output_dir.absolute()}")


if __name__ == "__main__":
    main()