Add HUB-SDK docs (#7775)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com>
Co-authored-by: Muhammad Rizwan Munawar <chr043416@gmail.com>
This commit is contained in:
Glenn Jocher 2024-01-23 18:58:55 +01:00 committed by GitHub
parent 67ae86f006
commit 1152a06cbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 153 additions and 41 deletions

View file

@ -33,24 +33,36 @@ from tqdm import tqdm
DOCS = Path(__file__).parent.resolve()
SITE = DOCS.parent / "site"
LANGUAGES = False
def build_docs():
def build_docs(use_languages=False, clone_repos=True):
"""Build docs using mkdocs."""
if SITE.exists():
print(f"Removing existing {SITE}")
shutil.rmtree(SITE)
# Get hub-sdk repo
if clone_repos:
repo = "https://github.com/ultralytics/hub-sdk"
local_dir = DOCS.parent / Path(repo).name
if not local_dir.exists():
os.system(f"git clone {repo} {local_dir}")
os.system(f"git -C {local_dir} pull") # update repo
shutil.rmtree(DOCS / "en/hub/sdk")
shutil.copytree(local_dir / "docs", DOCS / "en/hub/sdk")
shutil.rmtree(DOCS / "en/hub/sdk/reference") # temporarily delete reference until we find a solution for this
print(f"Cloned/Updated {repo} in {local_dir}")
# Build the main documentation
print(f"Building docs from {DOCS}")
subprocess.run(f"mkdocs build -f {DOCS}/mkdocs.yml", check=True, shell=True)
# Build other localized documentations
if LANGUAGES:
if use_languages:
for file in DOCS.glob("mkdocs_*.yml"):
print(f"Building MkDocs site with configuration file: {file}")
subprocess.run(f"mkdocs build -f {file}", check=True, shell=True)
update_html_links() # update .md in href links
print(f"Site built at {SITE}")
@ -104,21 +116,13 @@ def update_page_title(file_path: Path, new_title: str):
file.write(updated_content)
def update_html_head(key=""):
def update_html_head(script=""):
"""Update the HTML head section of each file."""
html_files = Path(SITE).rglob("*.html")
for html_file in tqdm(html_files, desc="Processing HTML files"):
with html_file.open("r", encoding="utf-8") as file:
html_content = file.read()
script = f"""
<script type="text/javascript" src="https://cdn.weglot.com/weglot.min.js"></script>
<script>
Weglot.initialize({{
api_key: '{key}'
}});
</script>
"""
if script in html_content: # script already in HTML file
return
@ -137,13 +141,8 @@ def main():
# Update titles
update_page_title(SITE / "404.html", new_title="Ultralytics Docs - Not Found")
# Update .md in href links
if LANGUAGES:
update_html_links()
# Update HTML file head section
if not LANGUAGES and False:
update_html_head(key=os.environ.get("WEGLOT_KEY"))
# update_html_head("")
# Show command to serve built website
print('Serve site at http://localhost:8000 with "python -m http.server --directory site"')