Skip to content

Commit

Permalink
Lazy version list for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed May 25, 2024
1 parent 150b5ff commit bb5f024
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions docs/source/_templates/sidebar/brand.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
<span class="sidebar-brand-text">{{ version }}</span>

<!-- Dropdown for different versions of the viser docs. Slightly hacky -->
<details style="padding: 0.5rem; background: var(--color-background-primary); border-radius: 0.5rem; border: 1px solid var(--color-sidebar-background-border);">
<summary style="cursor: pointer;">Versions</summary>
<div id="version-dropdown"></div>
</details>
<script>
(async () => {
var viserDocsVersionsPopulated = false;
async function viserDocsPopulateVersionDropDown () {
// Load the version list lazily... reduces likelihood of running into GitHub API rate limits.
if (viserDocsVersionsPopulated) {
return;
}
viserDocsVersionsPopulated = true;

// Populate the version list by polling the GitHub REST API.
console.log("Populating docs version list!")
const response = await fetch(
"https://api.github.com/repos/nerfstudio-project/viser/contents/versions?ref=gh-pages",
);
Expand All @@ -32,8 +36,15 @@
htmlString += "</ul>";
document.getElementById("version-dropdown").innerHTML =
htmlString;
})();
}
</script>
<details
style="padding: 0.5rem; background: var(--color-background-primary); border-radius: 0.5rem; border: 1px solid var(--color-sidebar-background-border);"
ontoggle="viserDocsPopulateVersionDropDown()"
>
<summary style="cursor: pointer;">Versions</summary>
<div id="version-dropdown"></div>
</details>
<!-- End dropdown -->
{% endblock brand_content %}
</div>
Expand Down

0 comments on commit bb5f024

Please sign in to comment.