From 426a584e2f14cf38cb5cd0e605e9812dda46da68 Mon Sep 17 00:00:00 2001 From: Matt Elliott Date: Mon, 18 Nov 2024 16:01:22 -0500 Subject: [PATCH] feat: add generic theme flavor --- .../flavors/generic/footer.jinja | 5 ++++ .../flavors/generic/header.jinja | 28 +++++++++++++++++++ .../flavors/generic/left-side-menu.jinja | 3 ++ src/rocm_docs/rocm_docs_theme/theme.conf | 8 ++++++ src/rocm_docs/theme.py | 17 +++++++++++ 5 files changed, 61 insertions(+) create mode 100644 src/rocm_docs/rocm_docs_theme/flavors/generic/footer.jinja create mode 100644 src/rocm_docs/rocm_docs_theme/flavors/generic/header.jinja create mode 100644 src/rocm_docs/rocm_docs_theme/flavors/generic/left-side-menu.jinja diff --git a/src/rocm_docs/rocm_docs_theme/flavors/generic/footer.jinja b/src/rocm_docs/rocm_docs_theme/flavors/generic/footer.jinja new file mode 100644 index 00000000..64cccb3a --- /dev/null +++ b/src/rocm_docs/rocm_docs_theme/flavors/generic/footer.jinja @@ -0,0 +1,5 @@ +{% macro license_link() -%} + {% if theme_license_link %} +
  • {{ theme_license_text if theme_license_text else "" }}
  • + {% endif %} +{%- endmacro -%} diff --git a/src/rocm_docs/rocm_docs_theme/flavors/generic/header.jinja b/src/rocm_docs/rocm_docs_theme/flavors/generic/header.jinja new file mode 100644 index 00000000..a9fe97da --- /dev/null +++ b/src/rocm_docs/rocm_docs_theme/flavors/generic/header.jinja @@ -0,0 +1,28 @@ +{% macro top_level_header(branch, latest_version, release_candidate_version) -%} + {% if theme_header_title %} + {% set header_title = theme_header_title %} + {% else %} + {% set header_title = project ~ " " ~ version %} + {% endif %} + + {% if theme_header_link %} + {% set header_link = theme_header_link %} + {% else %} + {% set header_link = "#" %} + {% endif %} + + {{ header_title }} +{%- endmacro -%} + +{% macro version_list() -%} + {% if theme_version_list_link %} + Version List + {% endif %} +{%- endmacro -%} + +{% +set nav_secondary_items = theme_nav_secondary_items if theme_nav_secondary_items else { + "GitHub": theme_repository_url if theme_repository_url else "#", + "Support": (theme_repository_url + "/issues/new/choose") if theme_repository_url else "#" +} +%} diff --git a/src/rocm_docs/rocm_docs_theme/flavors/generic/left-side-menu.jinja b/src/rocm_docs/rocm_docs_theme/flavors/generic/left-side-menu.jinja new file mode 100644 index 00000000..f95755d0 --- /dev/null +++ b/src/rocm_docs/rocm_docs_theme/flavors/generic/left-side-menu.jinja @@ -0,0 +1,3 @@ +{% +set main_doc_link = theme_main_doc_link if theme_main_doc_link else (project, "#") +%} diff --git a/src/rocm_docs/rocm_docs_theme/theme.conf b/src/rocm_docs/rocm_docs_theme/theme.conf index 13635ec0..04a618ae 100644 --- a/src/rocm_docs/rocm_docs_theme/theme.conf +++ b/src/rocm_docs/rocm_docs_theme/theme.conf @@ -9,3 +9,11 @@ show_toc_level = 1 flavor = rocm link_main_doc = True + +# Generic theme options +header_title = +header_link = +version_list_link = +nav_secondary_items = +license_link = +license_text = diff --git a/src/rocm_docs/theme.py b/src/rocm_docs/theme.py index cb172549..db522a19 100644 --- a/src/rocm_docs/theme.py +++ b/src/rocm_docs/theme.py @@ -117,6 +117,15 @@ def _update_theme_options(app: Sphinx) -> None: flavor = supported_flavors[0] theme_opts["flavor"] = flavor + # Set default generic theme options + if flavor == "generic": + theme_opts.setdefault("header_title", "") + theme_opts.setdefault("header_link", "#") + theme_opts.setdefault("version_list_link", None) + theme_opts.setdefault("nav_secondary_items", {}) + theme_opts.setdefault("license_link", None) + theme_opts.setdefault("license_text", "") + theme_opts.setdefault( "article_header_start", ["components/toggle-primary-sidebar.html", "breadcrumbs.html"], @@ -182,6 +191,14 @@ def setup(app: Sphinx) -> dict[str, Any]: app.connect("html-page-context", _add_custom_context) app.connect("builder-inited", _update_theme_options) + # Add theme option declarations + app.add_config_value("header_title", "", "html") + app.add_config_value("header_link", "#", "html") + app.add_config_value("version_list_link", None, "html") + app.add_config_value("nav_secondary_items", {}, "html", [dict]) + app.add_config_value("license_link", None, "html") + app.add_config_value("license_text", "", "html") + return { "parallel_read_safe": True, "parallel_write_safe": True,