sidebar.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <div class="sidebar-wrapper">
  2. {{ $currentPage := . }}
  3. <nav role="navigation" class="sidebar">
  4. <ul>
  5. <div id="docsearch"></div>
  6. <select id="version-select" class="version-dropdown" style="width: 100%; box-sizing: border-box;">
  7. </select>
  8. <br><br>
  9. {{ range .Site.Menus.main.ByWeight }}
  10. <li class="level-1 {{if .HasChildren }}has-children{{ else }}no-children{{ end }}">
  11. <a {{with .URL}}href="{{.}}"{{end}} class="{{if $currentPage.IsMenuCurrent "main" .}}active{{end}}">
  12. {{- if .HasChildren }}
  13. {{ readFile "static/images/icon_sidebar_expander.svg" | safeHTML }}
  14. {{ end }}
  15. {{.Name | markdownify}}
  16. </a>
  17. {{- if .HasChildren }}
  18. <ul>
  19. {{- range .Children }}
  20. <li class="level-2 {{if .HasChildren }}has-children{{ else }}no-children{{ end }}">
  21. <a {{with .URL}}href="{{.}}"{{end}} class="{{if $currentPage.IsMenuCurrent "main" .}}active{{end}}">
  22. {{- if .HasChildren }}
  23. {{ readFile "static/images/icon_sidebar_expander.svg" | safeHTML }}
  24. {{ end }}
  25. {{.Name | markdownify}}
  26. </a>
  27. {{- if .HasChildren }}
  28. <ul>
  29. {{- range .Children }}
  30. <li class="level-3 {{if .HasChildren }}has-children{{ else }}no-children{{ end }}">
  31. <a {{with .URL}}href="{{.}}"{{end}} class="{{if $currentPage.IsMenuCurrent "main" .}}active{{end}}">
  32. {{- if .HasChildren }}
  33. {{ readFile "static/images/icon_sidebar_expander.svg" | safeHTML }}
  34. {{ end }}
  35. {{.Name | markdownify}}
  36. </a>
  37. {{- if .HasChildren }}
  38. <ul>
  39. {{- range .Children }}
  40. <li class="level-4">
  41. <a href="{{.URL}}" class="{{if $currentPage.IsMenuCurrent "main" .}}active{{end}}">
  42. {{.Name | markdownify}}
  43. </a>
  44. </li>
  45. {{- end}}
  46. </ul>
  47. {{- end}}
  48. </li>
  49. {{- end}}
  50. </ul>
  51. {{- end}}
  52. </li>
  53. {{- end}}
  54. </ul>
  55. {{- end}}
  56. </li>
  57. {{- end}}
  58. </ul>
  59. </nav>
  60. <button class="close-topics" aria-label="Close the topics sidebar">
  61. <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>
  62. </button>
  63. </div>
  64. <script>
  65. document.addEventListener('DOMContentLoaded', function () {
  66. const versionSelect = document.getElementById('version-select');
  67. const currentPath = window.location.pathname;
  68. fetch('/docs/versions.json')
  69. .then( response => {
  70. if (!response.ok) {
  71. throw new Error('File not found');
  72. }
  73. return response.json();
  74. })
  75. .catch(() => {
  76. return fetch('{{ .Site.BaseURL }}versions.json')
  77. .then(response => {
  78. if (!response.ok) {
  79. throw new Error('Fallback file not found');
  80. }
  81. return response.json();
  82. });
  83. })
  84. .then(versions => {
  85. versions.forEach(version => {
  86. const option = document.createElement('option');
  87. option.value = version.base_url;
  88. option.textContent = version.name;
  89. versionSelect.appendChild(option);
  90. });
  91. const currentVersion = versions.filter(version => currentPath.includes(version.base_url))?.at(-1)?.base_url;
  92. if (currentVersion) {
  93. versionSelect.value = currentVersion;
  94. }
  95. versionSelect.addEventListener('change', function () {
  96. const baseUrl = '{{ .Site.BaseURL }}';
  97. const strippedBaseUrl = baseUrl.endsWith(currentVersion) ? baseUrl.slice(0, -currentVersion.length) : baseUrl;
  98. const selectedBaseUrl = strippedBaseUrl + versionSelect.value;
  99. if (selectedBaseUrl) {
  100. window.location.href = selectedBaseUrl;
  101. }
  102. });
  103. })
  104. .catch(error => console.error('Error fetching versions:', error));
  105. });
  106. </script>