-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulate_docs.py
executable file
·32 lines (26 loc) · 1.1 KB
/
populate_docs.py
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
#! /usr/bin/env python3
import subprocess
from pathlib import Path
def run_command(command, cwd=None):
result = subprocess.run(command, shell=True, cwd=cwd, capture_output=True, text=True)
if result.returncode != 0:
print(f"Error running command: {command}\n{result.stderr}")
return result.stdout
if Path('docs').exists():
print("Removing existing docs folder...")
run_command("rm -rf docs/*")
for repo in Path('src').iterdir():
build_command = 'zola '
if (repo / "config.extension.toml").exists():
build_command += '--config config.extension.toml build'
else:
build_command += f'build --base-url /docs/{repo.name}'
run_command(build_command, cwd=repo)
print(f"Build completed for: {repo.name}\n")
# Create branch directory in docs and move public folder content there
branch_dir = Path('docs') / repo.name
branch_dir.mkdir(parents=True, exist_ok=True)
run_command(f"mv {repo}/public/* {branch_dir}/")
# Copy data.json to docs directory if it exists in the repository
if Path('data.json').exists():
run_command("cp data.json docs/")