|
4 | 4 | <nav role="navigation" class="sidebar"> |
5 | 5 | <ul> |
6 | 6 | <div id="docsearch"></div> |
7 | | - <select id="version-select" class="version-dropdown" style="width: 100%; box-sizing: border-box;"> |
8 | | - </select> |
9 | | - <br><br> |
10 | 7 |
|
11 | 8 | {{ range .Site.Menus.main.ByWeight }} |
12 | 9 | <li class="level-1 {{if .HasChildren }}has-children{{ else }}no-children{{ end }}"> |
|
66 | 63 | <svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>Close</title><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M368 368L144 144M368 144L144 368"/></svg> |
67 | 64 | </button> |
68 | 65 | </div> |
69 | | - |
70 | | -<script> |
71 | | - document.addEventListener('DOMContentLoaded', function () { |
72 | | - const versionSelect = document.getElementById('version-select'); |
73 | | - const currentPath = window.location.pathname; |
74 | | - |
75 | | - fetch('/docs/versions.json') |
76 | | - .then( response => { |
77 | | - if (!response.ok) { |
78 | | - throw new Error('File not found'); |
79 | | - } |
80 | | - return response.json(); |
81 | | - }) |
82 | | - .catch(() => { |
83 | | - return fetch('{{ .Site.BaseURL }}versions.json') |
84 | | - .then(response => { |
85 | | - if (!response.ok) { |
86 | | - throw new Error('Fallback file not found'); |
87 | | - } |
88 | | - return response.json(); |
89 | | - }); |
90 | | - }) |
91 | | - .then(versions => { |
92 | | - versions.forEach(version => { |
93 | | - const option = document.createElement('option'); |
94 | | - option.value = version.base_url; |
95 | | - option.textContent = version.name; |
96 | | - versionSelect.appendChild(option); |
97 | | - }); |
98 | | - |
99 | | - const currentVersion = versions.filter(version => currentPath.includes(version.base_url))?.at(-1)?.base_url; |
100 | | - |
101 | | - if (currentVersion) { |
102 | | - versionSelect.value = currentVersion; |
103 | | - } |
104 | | - |
105 | | - versionSelect.addEventListener('change', function () { |
106 | | - const baseUrl = '{{ .Site.BaseURL }}'; |
107 | | - const strippedBaseUrl = baseUrl.endsWith(currentVersion) ? baseUrl.slice(0, -currentVersion.length) : baseUrl; |
108 | | - const selectedBaseUrl = strippedBaseUrl + versionSelect.value; |
109 | | - if (selectedBaseUrl) { |
110 | | - window.location.href = selectedBaseUrl; |
111 | | - } |
112 | | - }); |
113 | | - }) |
114 | | - .catch(error => console.error('Error fetching versions:', error)); |
115 | | - }); |
116 | | -</script> |
0 commit comments