mirror of
https://github.com/imfing/hextra.git
synced 2025-05-13 13:06:25 -04:00
Compare commits
6 Commits
23bb171e99
...
f5cfd1424d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f5cfd1424d | ||
![]() |
0c90c1aa50 | ||
![]() |
06eb8a66a1 | ||
![]() |
081ad8b84f | ||
![]() |
7593ef4ae4 | ||
![]() |
b70d729283 |
@ -1,8 +1,43 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
scrollToActiveItem();
|
initializeSidebar();
|
||||||
enableCollapsibles();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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() {
|
function enableCollapsibles() {
|
||||||
const buttons = document.querySelectorAll(".hextra-sidebar-collapsible-button");
|
const buttons = document.querySelectorAll(".hextra-sidebar-collapsible-button");
|
||||||
buttons.forEach(function (button) {
|
buttons.forEach(function (button) {
|
||||||
@ -16,21 +51,16 @@ function enableCollapsibles() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToActiveItem() {
|
function saveSidebarPosition(scrollPosition) {
|
||||||
const sidebarScrollbar = document.querySelector("aside.sidebar-container > .hextra-scrollbar");
|
localStorage.setItem('sidebarScrollPosition', scrollPosition);
|
||||||
const activeItems = document.querySelectorAll(".sidebar-active-item");
|
}
|
||||||
const visibleActiveItem = Array.from(activeItems).find(function (activeItem) {
|
|
||||||
return activeItem.getBoundingClientRect().height > 0;
|
function restoreSidebarPosition(sidebarScrollbar) {
|
||||||
});
|
const savedPosition = localStorage.getItem('sidebarScrollPosition');
|
||||||
|
|
||||||
if (!visibleActiveItem) {
|
if (savedPosition !== null) {
|
||||||
return;
|
requestAnimationFrame(() => {
|
||||||
}
|
sidebarScrollbar.scrollTop = parseInt(savedPosition);
|
||||||
|
});
|
||||||
const yOffset = visibleActiveItem.clientHeight;
|
}
|
||||||
const yDistance = visibleActiveItem.getBoundingClientRect().top - sidebarScrollbar.getBoundingClientRect().top;
|
|
||||||
sidebarScrollbar.scrollTo({
|
|
||||||
behavior: "instant",
|
|
||||||
top: yDistance - yOffset
|
|
||||||
});
|
|
||||||
}
|
}
|
10
layouts/shortcodes/hextra/hero-section.html
Normal file
10
layouts/shortcodes/hextra/hero-section.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{{- $style := .Get "style" -}}
|
||||||
|
{{- $heading := int (strings.TrimPrefix "h" (.Get "heading" | default "h2")) -}}
|
||||||
|
{{- $size := cond (ge $heading 4) "xl" (cond (eq $heading 3) "2xl" "4xl") -}}
|
||||||
|
|
||||||
|
<h{{ $heading }}
|
||||||
|
class="not-prose hx-text-{{ $size }} hx-font-bold hx-leading-none hx-tracking-tighter md:hx-text-3xl hx-py-2 hx-bg-clip-text hx-text-transparent hx-bg-gradient-to-r hx-from-gray-900 hx-to-gray-600 dark:hx-from-gray-100 dark:hx-to-gray-400"
|
||||||
|
{{ with $style }}style="{{ . | safeCSS }}"{{ end }}
|
||||||
|
>
|
||||||
|
{{ .Inner | markdownify }}
|
||||||
|
</h{{ $heading }}>
|
Loading…
x
Reference in New Issue
Block a user