Simplify build_docs.py (#18910)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
8a185f6ebe
commit
305a298ae2
1 changed files with 18 additions and 8 deletions
|
|
@ -49,23 +49,29 @@ def create_vercel_config():
|
||||||
|
|
||||||
def prepare_docs_markdown(clone_repos=True):
|
def prepare_docs_markdown(clone_repos=True):
|
||||||
"""Build docs using mkdocs."""
|
"""Build docs using mkdocs."""
|
||||||
if SITE.exists():
|
print("Removing existing build artifacts")
|
||||||
print(f"Removing existing {SITE}")
|
shutil.rmtree(SITE, ignore_errors=True)
|
||||||
shutil.rmtree(SITE)
|
shutil.rmtree(DOCS / "repos", ignore_errors=True)
|
||||||
|
|
||||||
# Get hub-sdk repo
|
|
||||||
if clone_repos:
|
if clone_repos:
|
||||||
|
# Get hub-sdk repo
|
||||||
repo = "https://github.com/ultralytics/hub-sdk"
|
repo = "https://github.com/ultralytics/hub-sdk"
|
||||||
local_dir = DOCS.parent / Path(repo).name
|
local_dir = DOCS / "repos" / Path(repo).name
|
||||||
if not local_dir.exists():
|
os.system(f"git clone {repo} {local_dir} --depth 1 --single-branch --branch main")
|
||||||
os.system(f"git clone {repo} {local_dir}")
|
|
||||||
os.system(f"git -C {local_dir} pull") # update repo
|
|
||||||
shutil.rmtree(DOCS / "en/hub/sdk", ignore_errors=True) # delete if exists
|
shutil.rmtree(DOCS / "en/hub/sdk", ignore_errors=True) # delete if exists
|
||||||
shutil.copytree(local_dir / "docs", DOCS / "en/hub/sdk") # for docs
|
shutil.copytree(local_dir / "docs", DOCS / "en/hub/sdk") # for docs
|
||||||
shutil.rmtree(DOCS.parent / "hub_sdk", ignore_errors=True) # delete if exists
|
shutil.rmtree(DOCS.parent / "hub_sdk", ignore_errors=True) # delete if exists
|
||||||
shutil.copytree(local_dir / "hub_sdk", DOCS.parent / "hub_sdk") # for mkdocstrings
|
shutil.copytree(local_dir / "hub_sdk", DOCS.parent / "hub_sdk") # for mkdocstrings
|
||||||
print(f"Cloned/Updated {repo} in {local_dir}")
|
print(f"Cloned/Updated {repo} in {local_dir}")
|
||||||
|
|
||||||
|
# Get docs repo
|
||||||
|
repo = "https://github.com/ultralytics/docs"
|
||||||
|
local_dir = DOCS / "repos" / Path(repo).name
|
||||||
|
os.system(f"git clone {repo} {local_dir} --depth 1 --single-branch --branch main")
|
||||||
|
shutil.rmtree(DOCS / "en/compare", ignore_errors=True) # delete if exists
|
||||||
|
shutil.copytree(local_dir / "docs/en/compare", DOCS / "en/compare") # for docs
|
||||||
|
print(f"Cloned/Updated {repo} in {local_dir}")
|
||||||
|
|
||||||
# Add frontmatter
|
# Add frontmatter
|
||||||
for file in tqdm((DOCS / "en").rglob("*.md"), desc="Adding frontmatter"):
|
for file in tqdm((DOCS / "en").rglob("*.md"), desc="Adding frontmatter"):
|
||||||
update_markdown_files(file)
|
update_markdown_files(file)
|
||||||
|
|
@ -317,6 +323,10 @@ def main():
|
||||||
# Minify files
|
# Minify files
|
||||||
minify_files(html=False, css=False, js=False)
|
minify_files(html=False, css=False, js=False)
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
shutil.rmtree(DOCS.parent / "hub_sdk", ignore_errors=True)
|
||||||
|
shutil.rmtree(DOCS / "repos", ignore_errors=True)
|
||||||
|
|
||||||
# Show command to serve built website
|
# Show command to serve built website
|
||||||
print('Docs built correctly ✅\nServe site at http://localhost:8000 with "python -m http.server --directory site"')
|
print('Docs built correctly ✅\nServe site at http://localhost:8000 with "python -m http.server --directory site"')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue