|
9 | 9 | <img class="sidebar-logo only-dark" src="{{ pathto('_static/' + theme_dark_logo, 1) }}" alt="logo" /> |
10 | 10 | </div> |
11 | 11 | {%- endif %} |
12 | | - <span class="sidebar-brand-text">{{ version }}</span> |
| 12 | + <!-- <span class="sidebar-brand-text">{{ project }}</span> --> |
13 | 13 |
|
14 | | - <!-- Dropdown for different versions of the viser docs. Slightly hacky --> |
| 14 | + {% endblock brand_content %} |
| 15 | +</div> |
| 16 | + |
| 17 | +<!-- Dropdown for different versions of the viser docs. Slightly hacky. --> |
| 18 | +<div style="padding: 0 1em;"> |
15 | 19 | <script> |
16 | 20 | var viserDocsVersionsPopulated = false; |
| 21 | + |
| 22 | + function viserMemoizeHelper(fn) { |
| 23 | + const cacheKey = fn.name || 'memoizedFunction'; |
| 24 | + const ttl = 3 * 60 * 1000; // 3 minutes in milliseconds. |
| 25 | + |
| 26 | + return async function(...args) { |
| 27 | + const now = Date.now(); |
| 28 | + const cache = JSON.parse(localStorage.getItem(cacheKey)) || {}; |
| 29 | + if (cache.timestamp && (now - cache.timestamp < ttl)) { |
| 30 | + console.log("Using cached value"); |
| 31 | + return cache.value; |
| 32 | + } |
| 33 | + const value = await fn(...args); |
| 34 | + if (value === null) { |
| 35 | + console.log("Using cached value (failed to recompute)"); |
| 36 | + return cache.value |
| 37 | + } |
| 38 | + localStorage.setItem(cacheKey, JSON.stringify({ value, timestamp: now })); |
| 39 | + return value; |
| 40 | + }; |
| 41 | + } |
| 42 | + async function getVersionListViaGithubApi() { |
| 43 | + console.log("Polling GitHub REST API"); |
| 44 | + const response = await fetch( |
| 45 | + "https://api.github.com/repos/nerfstudio-project/viser/contents/versions?ref=gh-pages", |
| 46 | + ); |
| 47 | + if (await response.status === 403) { |
| 48 | + console.error(await response.json()); |
| 49 | + return null; |
| 50 | + } |
| 51 | + return await response.json(); |
| 52 | + } |
17 | 53 | async function viserDocsPopulateVersionDropDown () { |
18 | 54 | // Load the version list lazily... reduces likelihood of running into GitHub API rate limits. |
19 | 55 | if (viserDocsVersionsPopulated) { |
|
23 | 59 |
|
24 | 60 | // Populate the version list by polling the GitHub REST API. |
25 | 61 | console.log("Populating docs version list!") |
26 | | - const response = await fetch( |
27 | | - "https://api.github.com/repos/nerfstudio-project/viser/contents/versions?ref=gh-pages", |
28 | | - ); |
29 | | - const data = await response.json(); |
| 62 | + const data = viserMemoizeHelper(getVersionListViaGithubApi)(); |
30 | 63 | let htmlString = "<ul style='margin: 0.5rem 0 0 0'>"; |
31 | 64 | htmlString += `<li><a href="https://viser.studio/latest">latest</a></li>`; |
32 | 65 | for (let file of data) { |
|
42 | 75 | style="padding: 0.5rem; background: var(--color-background-primary); border-radius: 0.5rem; border: 1px solid var(--color-sidebar-background-border);" |
43 | 76 | ontoggle="viserDocsPopulateVersionDropDown()" |
44 | 77 | > |
45 | | - <summary style="cursor: pointer;">Versions</summary> |
| 78 | + <summary style="cursor: pointer;"><strong>Version:</strong> <em>{{ version }}</em></summary> |
46 | 79 | <div id="version-dropdown"></div> |
47 | 80 | </details> |
48 | 81 | <!-- End dropdown --> |
49 | | - {% endblock brand_content %} |
50 | 82 | </div> |
51 | 83 |
|
52 | 84 | <div style="text-align: left; padding: 1em"> |
|
0 commit comments