Skip to content

Commit

Permalink
Merge pull request #769 from samjwu/header
Browse files Browse the repository at this point in the history
fix: Get header version from URL instead of theme.conf
  • Loading branch information
samjwu committed May 22, 2024
2 parents 17e66e8 + 224ea34 commit 5c5c435
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/rocm_docs/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ def _update_theme_configs(
) -> None:
"""Update configurations for use in theme.py"""
latest_version = requests.get(
"https://github.com/raw/RadeonOpenCompute/rocm-docs-core/header-versions/latest_version.txt"
"https://github.com/raw/ROCm/rocm-docs-core/header-versions/latest_version.txt"
).text.strip("\r\n")
latest_version_string = f"docs-{latest_version}"
release_candidate = requests.get(
"https://github.com/raw/RadeonOpenCompute/rocm-docs-core/header-versions/release_candidate.txt"
"https://github.com/raw/ROCm/rocm-docs-core/header-versions/release_candidate.txt"
).text.strip("\r\n")
release_candidate_string = f"docs-{release_candidate}"

Expand Down
6 changes: 5 additions & 1 deletion src/rocm_docs/rocm_docs_theme/sections/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<img src="{{ pathto('_static/images/amd-header-logo.svg',1) }}" alt="AMD Logo" title="AMD Logo" width="90" class="d-inline-block align-text-top hover-opacity"/>
</a>
<div class="vr vr mx-40 my-25"></div>
{{ top_level_header(theme_repository_branch | replace("docs-", ""), theme_header_latest_version, theme_header_release_candidate_version) }}
{{ top_level_header(
theme_repository_branch | replace("docs-", ""),
header_latest_version,
header_release_candidate_version
) }}
{{ version_list() }}
</div>
<div class="icon-nav text-center d-flex ms-auto">
Expand Down
3 changes: 0 additions & 3 deletions src/rocm_docs/rocm_docs_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ show_toc_level = 1
flavor = rocm

link_main_doc = True

header_latest_version = 6.1.1
header_release_candidate_version = 6.2.0
44 changes: 38 additions & 6 deletions src/rocm_docs/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@
logger = sphinx.util.logging.getLogger(__name__)


def _get_version_from_url(url: str) -> str:
try:
response = requests.get(url)
return response.text.strip()
except requests.RequestException as e:
print(f"Error in rocm-docs-core _get_version_from_url: {e}")
return ""


def _add_custom_context(
app: Sphinx, # noqa: ARG001
pagename: str, # noqa: ARG001
templatename: str, # noqa: ARG001
context: dict[str, str],
doctree: object, # noqa: ARG001
) -> None:
header_latest_version = _get_version_from_url(
"https://github.com/raw/ROCm/rocm-docs-core/header-versions/latest_version.txt"
)

header_release_candidate_version = _get_version_from_url(
"https://github.com/raw/ROCm/rocm-docs-core/header-versions/release_candidate.txt"
)

context["header_latest_version"] = header_latest_version
context["header_release_candidate_version"] = (
header_release_candidate_version
)


def _update_repo_opts(srcdir: str, theme_opts: dict[str, Any]) -> None:
default_branch_options: dict[str, Any] = {
"use_edit_page_button": False,
Expand Down Expand Up @@ -88,21 +118,22 @@ def _update_theme_options(app: Sphinx) -> None:
0, "components/left-side-menu"
)

header_latest_version = requests.get(
header_latest_version = _get_version_from_url(
"https://github.com/raw/RadeonOpenCompute/rocm-docs-core/header-versions/latest_version.txt"
).text.strip("\r\n")
header_release_candidate_version = requests.get(
)

header_release_candidate_version = _get_version_from_url(
"https://github.com/raw/RadeonOpenCompute/rocm-docs-core/header-versions/release_candidate.txt"
).text.strip("\r\n")
)

default_config_opts = {
"html_show_sphinx": False,
"html_favicon": "https://www.amd.com/themes/custom/amd/favicon.ico",
"notfound_context": {"title": "404 - Page Not Found"},
"notfound_template": "404.html",
"html_context": {
"theme_header_latest_version": header_latest_version,
"theme_header_release_candidate_version": header_release_candidate_version,
"header_latest_version": header_latest_version,
"header_release_candidate_version": header_release_candidate_version,
},
}
for key, default in default_config_opts.items():
Expand Down Expand Up @@ -132,6 +163,7 @@ def setup(app: Sphinx) -> dict[str, Any]:
]:
app.add_css_file(css)

app.connect("html-page-context", _add_custom_context)
app.connect("builder-inited", _update_theme_options)

return {
Expand Down

0 comments on commit 5c5c435

Please sign in to comment.