mirror of
https://github.com/hunvreus/basecoat.git
synced 2026-11-14 14:08:18 +00:00
Removing current page code from sidebar.js
This commit is contained in:
@@ -1,6 +1,43 @@
|
||||
{% from "sidebar.njk" import sidebar %}
|
||||
{% from "popover.njk" import popover %}
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
if (!sidebar) return;
|
||||
|
||||
const updateCurrentLinks = () => {
|
||||
const currentPath = window.location.pathname.replace(/\/$/, '');
|
||||
const currentSearch = window.location.search;
|
||||
const currentKey = `${currentPath}${currentSearch}`;
|
||||
|
||||
sidebar.querySelectorAll('a, button').forEach((item) => {
|
||||
const href = item.getAttribute('href');
|
||||
if (!href) {
|
||||
item.removeAttribute('aria-current');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = new URL(href, window.location.origin);
|
||||
const itemPath = url.pathname.replace(/\/$/, '');
|
||||
const itemKey = `${itemPath}${url.search}`;
|
||||
|
||||
if (itemKey === currentKey) {
|
||||
item.setAttribute('aria-current', 'page');
|
||||
} else {
|
||||
item.removeAttribute('aria-current');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('htmx:afterSettle', updateCurrentLinks);
|
||||
window.addEventListener('popstate', updateCurrentLinks);
|
||||
updateCurrentLinks();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
{% set footer %}
|
||||
{% set trigger %}
|
||||
<img src="https://github.com/hunvreus.png" class="rounded-lg shrink-0 size-8">
|
||||
@@ -136,4 +173,4 @@
|
||||
footer=footer,
|
||||
content_attrs={ "class": "scrollbar [&_[data-new-link]::after]:content-['New'] [&_[data-new-link]::after]:ml-auto [&_[data-new-link]::after]:text-xs [&_[data-new-link]::after]:font-medium [&_[data-new-link]::after]:bg-sidebar-primary [&_[data-new-link]::after]:text-sidebar-primary-foreground [&_[data-new-link]::after]:px-2 [&_[data-new-link]::after]:py-0.5 [&_[data-new-link]::after]:rounded-md" },
|
||||
menu=menu
|
||||
) }}
|
||||
) }}
|
||||
Reference in New Issue
Block a user