diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index 8acb756b8e..1cb46f08f5 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -9,6 +9,7 @@ from pathlib import Path from typing import Optional, List, Union +import git from git import Repo from docutils import nodes from docutils.statemachine import StringList, string2lines @@ -29,6 +30,7 @@ class ImportProjectsConfig: @dataclass class Project: + name: str source: str dest: str local: bool = False @@ -99,6 +101,16 @@ def update_sys_path_for_flytekit(import_project_config: ImportProjectsConfig): sys.path.insert(0, dir_path) +def update_html_context(project: Project, tag: str, commit: str, config: Config): + tag_url = f"{project.source}/releases/tag/{tag}" + commit_url = f"{project.source}/tree/{commit}" + + config.html_context[f"{project.name}_tag"] = tag + config.html_context[f"{project.name}_tag_url"] = tag_url + config.html_context[f"{project.name}_commit"] = commit + config.html_context[f"{project.name}_commit_url"] = commit_url + + def import_projects(app: Sphinx, config: Config): """Clone projects from git or copy from local directory.""" projects = [Project(**p) for p in config.import_projects] @@ -112,17 +124,34 @@ def import_projects(app: Sphinx, config: Config): ): (srcdir / _dir).mkdir(parents=True, exist_ok=True) + if not hasattr(config, "html_context"): + config.html_context = {} + + show_repo_tags = False for project in projects: if project.local: local_dir = srcdir / project.source + try: + repo = Repo(local_dir) + show_repo_tags = True + except git.InvalidGitRepositoryError: + repo = None else: local_dir = srcdir / import_projects_config.clone_dir / project.dest shutil.rmtree(local_dir, ignore_errors=True) - Repo.clone_from(project.source, local_dir) + repo = Repo.clone_from(project.source, local_dir) + show_repo_tags = True local_docs_path = local_dir / project.docs_path dest_docs_dir = srcdir / project.dest + # use the latest git tag when building docs + if repo: + tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) + tag = tags[-1] + update_html_context(project, str(tag), str(tag.commit)[:7], config) + repo.git.checkout(str(tag)) + if project.refresh or not dest_docs_dir.exists(): shutil.rmtree(dest_docs_dir, ignore_errors=True) shutil.copytree(local_docs_path, dest_docs_dir, dirs_exist_ok=True) @@ -134,6 +163,8 @@ def import_projects(app: Sphinx, config: Config): else: subprocess.run(project.cmd) + config.html_context["show_repo_tags"] = show_repo_tags + # remove cloned directories shutil.rmtree(import_projects_config.clone_dir) diff --git a/docs/_templates/page.html b/docs/_templates/page.html new file mode 100644 index 0000000000..582062c95e --- /dev/null +++ b/docs/_templates/page.html @@ -0,0 +1,227 @@ +{% extends "base.html" %} + +{% block body -%} +{{ super() }} +{% include "partials/icons.html" %} + + + + + + +{% if theme_announcement -%} +