1313import argparse
1414import shutil
1515from pathlib import Path
16+ from typing import Callable
1617
1718
1819def add_frontmatter (content : str , title : str , description : str , icon : str ) -> str :
@@ -38,6 +39,81 @@ def add_frontmatter(content: str, title: str, description: str, icon: str) -> st
3839 return frontmatter + content
3940
4041
42+ def copy_file_with_extension_change (
43+ source : Path , dest_dir : Path , new_extension : str = ".mdx"
44+ ) -> None :
45+ """
46+ Copy a single file to destination directory with extension change.
47+
48+ Args:
49+ source: Source file path
50+ dest_dir: Destination directory
51+ new_extension: New file extension (default: .mdx)
52+ """
53+ if not source .exists ():
54+ print (f"Warning: { source } does not exist" )
55+ return
56+
57+ dest = dest_dir / source .with_suffix (new_extension ).name
58+ shutil .copy2 (source , dest )
59+ print (f" ✓ { source .name } -> { dest .name } " )
60+
61+
62+ def copy_files_from_directory (
63+ source_dir : Path , dest_dir : Path , pattern : str = "*.md" , new_extension : str = ".mdx"
64+ ) -> None :
65+ """
66+ Copy all files matching pattern from source directory to destination with extension change.
67+
68+ Args:
69+ source_dir: Source directory
70+ dest_dir: Destination directory
71+ pattern: File pattern to match (default: *.md)
72+ new_extension: New file extension (default: .mdx)
73+ """
74+ if not source_dir .exists ():
75+ print (f"Warning: { source_dir } does not exist" )
76+ return
77+
78+ print (f"Copying files from { source_dir } to { dest_dir } " )
79+ for file in source_dir .glob (pattern ):
80+ dest = dest_dir / file .with_suffix (new_extension ).name
81+ shutil .copy2 (file , dest )
82+ print (f" ✓ { file .name } -> { dest .name } " )
83+
84+
85+ def copy_file_with_transformation (
86+ source : Path ,
87+ dest_dir : Path ,
88+ transform_fn : Callable [[str ], str ],
89+ new_extension : str = ".mdx" ,
90+ dest_filename : str | None = None ,
91+ ) -> None :
92+ """
93+ Copy a file with content transformation.
94+
95+ Args:
96+ source: Source file path
97+ dest_dir: Destination directory
98+ transform_fn: Function to transform file content
99+ new_extension: New file extension (default: .mdx)
100+ dest_filename: Optional custom destination filename (without extension)
101+ """
102+ if not source .exists ():
103+ print (f"Warning: { source } does not exist" )
104+ return
105+
106+ if dest_filename :
107+ dest = dest_dir / f"{ dest_filename } { new_extension } "
108+ else :
109+ dest = dest_dir / source .with_suffix (new_extension ).name
110+
111+ content = source .read_text (encoding = "utf-8" )
112+ transformed_content = transform_fn (content )
113+ dest .write_text (transformed_content , encoding = "utf-8" )
114+ print (f" ✓ { source .name } -> { dest .name } (transformed)" )
115+
116+
41117def copy_docs (sdk_root : Path , docs_root : Path ) -> None :
42118 """
43119 Copy generated documentation files to the docs repository.
@@ -49,52 +125,29 @@ def copy_docs(sdk_root: Path, docs_root: Path) -> None:
49125 # Source paths
50126 build_dir = sdk_root / "build" / "docs" / "content"
51127 fishaudio_dir = build_dir / "fishaudio"
52- fish_audio_sdk_file = build_dir / "fish_audio_sdk.md"
53128 index_file = build_dir / "index.md"
54129
55- # Destination paths
56- module_ref_dir = docs_root / "sdk-reference" / "python" / "module-reference"
57- python_sdk_dir = docs_root / "sdk-reference" / "python"
130+ # Destination path (flat structure - all files go to the same directory)
131+ python_sdk_dir = docs_root / "api-reference" / "sdk" / "python"
58132
59- # Create destination directories
60- module_ref_dir .mkdir (parents = True , exist_ok = True )
133+ # Create destination directory
61134 python_sdk_dir .mkdir (parents = True , exist_ok = True )
62135
63136 # Copy fishaudio module reference files
64- if fishaudio_dir .exists ():
65- print (f"Copying files from { fishaudio_dir } to { module_ref_dir } " )
66- for md_file in fishaudio_dir .glob ("*.md" ):
67- dest = module_ref_dir / md_file .name
68- shutil .copy2 (md_file , dest )
69- print (f" ✓ { md_file .name } " )
70- else :
71- print (f"Warning: { fishaudio_dir } does not exist" )
137+ copy_files_from_directory (fishaudio_dir , python_sdk_dir )
72138
73- # Copy fish_audio_sdk.md
74- if fish_audio_sdk_file .exists ():
75- dest = module_ref_dir / fish_audio_sdk_file .name
76- shutil .copy2 (fish_audio_sdk_file , dest )
77- print (f" ✓ { fish_audio_sdk_file .name } " )
78- else :
79- print (f"Warning: { fish_audio_sdk_file } does not exist" )
80-
81- # Copy index.md to python directory with frontmatter
82- if index_file .exists ():
83- dest = python_sdk_dir / index_file .name
84- # Read original content
85- content = index_file .read_text (encoding = "utf-8" )
86- # Add Mintlify frontmatter
87- content_with_frontmatter = add_frontmatter (
139+ # Copy index.md to python directory as overview.mdx with frontmatter
140+ copy_file_with_transformation (
141+ index_file ,
142+ python_sdk_dir ,
143+ lambda content : add_frontmatter (
88144 content ,
89145 title = "Python SDK" ,
90146 description = "Fish Audio Python SDK for text-to-speech and voice cloning" ,
91147 icon = "python" ,
92- )
93- # Write to destination
94- dest .write_text (content_with_frontmatter , encoding = "utf-8" )
95- print (f" ✓ { index_file .name } -> { python_sdk_dir } (with frontmatter)" )
96- else :
97- print (f"Warning: { index_file } does not exist" )
148+ ),
149+ dest_filename = "overview" ,
150+ )
98151
99152 print ("\n Documentation copy completed successfully!" )
100153
0 commit comments