mirror of
https://github.com/imfing/hextra.git
synced 2025-05-13 00:16:25 -04:00
Compare commits
7 Commits
2e255127af
...
23bb171e99
Author | SHA1 | Date | |
---|---|---|---|
![]() |
23bb171e99 | ||
![]() |
fe2271b60b | ||
![]() |
bd34a5bad3 | ||
![]() |
06eb8a66a1 | ||
![]() |
081ad8b84f | ||
![]() |
7593ef4ae4 | ||
![]() |
b70d729283 |
@ -1,8 +1,43 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
scrollToActiveItem();
|
||||
enableCollapsibles();
|
||||
initializeSidebar();
|
||||
});
|
||||
|
||||
function initializeSidebar() {
|
||||
const sidebarScrollbar = document.querySelector("aside.sidebar-container > .hextra-scrollbar");
|
||||
if (!sidebarScrollbar) return;
|
||||
|
||||
enableCollapsibles();
|
||||
restoreSidebarPosition(sidebarScrollbar);
|
||||
|
||||
const debouncedSave = debounce((position) => {
|
||||
saveSidebarPosition(position);
|
||||
}, 150);
|
||||
|
||||
sidebarScrollbar.addEventListener('scroll', function() {
|
||||
debouncedSave(this.scrollTop);
|
||||
});
|
||||
|
||||
document.querySelectorAll('a').forEach(link => {
|
||||
if (link.hostname === window.location.hostname) {
|
||||
link.addEventListener('click', function(e) {
|
||||
saveSidebarPosition(sidebarScrollbar.scrollTop);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function executedFunction(...args) {
|
||||
const later = () => {
|
||||
clearTimeout(timeout);
|
||||
func(...args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
}
|
||||
|
||||
function enableCollapsibles() {
|
||||
const buttons = document.querySelectorAll(".hextra-sidebar-collapsible-button");
|
||||
buttons.forEach(function (button) {
|
||||
@ -16,21 +51,16 @@ function enableCollapsibles() {
|
||||
});
|
||||
}
|
||||
|
||||
function scrollToActiveItem() {
|
||||
const sidebarScrollbar = document.querySelector("aside.sidebar-container > .hextra-scrollbar");
|
||||
const activeItems = document.querySelectorAll(".sidebar-active-item");
|
||||
const visibleActiveItem = Array.from(activeItems).find(function (activeItem) {
|
||||
return activeItem.getBoundingClientRect().height > 0;
|
||||
});
|
||||
|
||||
if (!visibleActiveItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
const yOffset = visibleActiveItem.clientHeight;
|
||||
const yDistance = visibleActiveItem.getBoundingClientRect().top - sidebarScrollbar.getBoundingClientRect().top;
|
||||
sidebarScrollbar.scrollTo({
|
||||
behavior: "instant",
|
||||
top: yDistance - yOffset
|
||||
});
|
||||
function saveSidebarPosition(scrollPosition) {
|
||||
localStorage.setItem('sidebarScrollPosition', scrollPosition);
|
||||
}
|
||||
|
||||
function restoreSidebarPosition(sidebarScrollbar) {
|
||||
const savedPosition = localStorage.getItem('sidebarScrollPosition');
|
||||
|
||||
if (savedPosition !== null) {
|
||||
requestAnimationFrame(() => {
|
||||
sidebarScrollbar.scrollTop = parseInt(savedPosition);
|
||||
});
|
||||
}
|
||||
}
|
@ -12,6 +12,13 @@ Open source projects powered by Hextra
|
||||
</p>
|
||||
|
||||
{{< cards >}}
|
||||
{{< card
|
||||
link="https://github.com/modelcontextprotocol/specification"
|
||||
title="Model Context Protocol Specification"
|
||||
image="https://github.com/user-attachments/assets/1bb4f952-b8fc-43b5-9cbd-cd7213c2ba90"
|
||||
imageStyle="object-fit:cover; aspect-ratio:16/9;"
|
||||
>}}
|
||||
|
||||
{{< card
|
||||
link="https://github.com/jonaspleyer/cellular_raza"
|
||||
title="cellular_raza"
|
||||
@ -84,7 +91,7 @@ Open source projects powered by Hextra
|
||||
link="https://hoa.moe/"
|
||||
title="HITSZ OpenAuto"
|
||||
image="https://raw.githubusercontent.com/HITSZ-OpenAuto/hoa.moe/main/static/images/showcase-new.png"
|
||||
imageStyle="object-fit:cover; aspect-ratio:16/9;"
|
||||
imageStyle="object-fit:cover; aspect-ratio:16/9;"
|
||||
>}}
|
||||
|
||||
{{< card
|
||||
|
@ -37,9 +37,32 @@
|
||||
{{- $mermaidJS := resources.Get "lib/mermaid/mermaid.min.js" | fingerprint -}}
|
||||
<script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Store original mermaid code for each diagram
|
||||
document.querySelectorAll(".mermaid").forEach(el => {
|
||||
el.dataset.original = el.innerHTML;
|
||||
});
|
||||
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
|
||||
let timeout;
|
||||
new MutationObserver(() => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
document.querySelectorAll(".mermaid").forEach(el => {
|
||||
// Reset to original content, preserving HTML
|
||||
el.innerHTML = el.dataset.original;
|
||||
el.removeAttribute("data-processed");
|
||||
});
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
mermaid.init();
|
||||
}, 150);
|
||||
}).observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{{- end -}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user