Skip to content

Commit 353c64c

Browse files
committed
feat: add script to copy generated documentation files to the docs repository
Signed-off-by: James Ding <[email protected]>
1 parent 2b44d60 commit 353c64c

File tree

2 files changed

+131
-5
lines changed

2 files changed

+131
-5
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ jobs:
3232
repository: ${{ vars.DOCS_REPO }}
3333
path: docs
3434

35-
- name: Create module reference directory
36-
run: mkdir -p docs/sdk-reference/python/module-reference
37-
3835
- name: Copy generated documentation
39-
run: |
40-
cp sdk/build/docs/content/fishaudio/*.md docs/sdk-reference/python/module-reference/
36+
run: uv run python sdk/scripts/copy_docs.py sdk docs
4137

4238
- name: Create Pull Request
4339
uses: peter-evans/create-pull-request@v6

scripts/copy_docs.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to copy generated documentation files to the docs repository.
4+
5+
Usage:
6+
python scripts/copy_docs.py <sdk_root> <docs_root>
7+
8+
Example:
9+
python scripts/copy_docs.py . ../docs
10+
python scripts/copy_docs.py sdk docs # In CI context
11+
"""
12+
13+
import argparse
14+
import shutil
15+
from pathlib import Path
16+
17+
18+
def add_frontmatter(content: str, title: str, description: str, icon: str) -> str:
19+
"""
20+
Add Mintlify frontmatter to markdown content.
21+
22+
Args:
23+
content: Original markdown content
24+
title: Page title
25+
description: Page description
26+
icon: Icon name
27+
28+
Returns:
29+
Content with frontmatter prepended
30+
"""
31+
frontmatter = f"""---
32+
title: "{title}"
33+
description: "{description}"
34+
icon: "{icon}"
35+
---
36+
37+
"""
38+
return frontmatter + content
39+
40+
41+
def copy_docs(sdk_root: Path, docs_root: Path) -> None:
42+
"""
43+
Copy generated documentation files to the docs repository.
44+
45+
Args:
46+
sdk_root: Root directory of the fish-audio-python SDK
47+
docs_root: Root directory of the docs repository
48+
"""
49+
# Source paths
50+
build_dir = sdk_root / "build" / "docs" / "content"
51+
fishaudio_dir = build_dir / "fishaudio"
52+
fish_audio_sdk_file = build_dir / "fish_audio_sdk.md"
53+
index_file = build_dir / "index.md"
54+
55+
# Destination paths
56+
module_ref_dir = docs_root / "sdk-reference" / "python" / "module-reference"
57+
python_sdk_dir = docs_root / "sdk-reference" / "python"
58+
59+
# Create destination directories
60+
module_ref_dir.mkdir(parents=True, exist_ok=True)
61+
python_sdk_dir.mkdir(parents=True, exist_ok=True)
62+
63+
# 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")
72+
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(
88+
content,
89+
title="Python SDK",
90+
description="Fish Audio Python SDK for text-to-speech and voice cloning",
91+
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")
98+
99+
print("\nDocumentation copy completed successfully!")
100+
101+
102+
def main() -> None:
103+
parser = argparse.ArgumentParser(
104+
description="Copy generated documentation files to the docs repository"
105+
)
106+
parser.add_argument(
107+
"sdk_root",
108+
type=Path,
109+
help="Root directory of the fish-audio-python SDK",
110+
)
111+
parser.add_argument(
112+
"docs_root",
113+
type=Path,
114+
help="Root directory of the docs repository",
115+
)
116+
117+
args = parser.parse_args()
118+
119+
# Validate paths
120+
if not args.sdk_root.exists():
121+
parser.error(f"SDK root directory does not exist: {args.sdk_root}")
122+
123+
if not args.docs_root.exists():
124+
parser.error(f"Docs root directory does not exist: {args.docs_root}")
125+
126+
copy_docs(args.sdk_root, args.docs_root)
127+
128+
129+
if __name__ == "__main__":
130+
main()

0 commit comments

Comments
 (0)