mirror of
https://github.com/imfing/hextra.git
synced 2025-07-08 15:47:26 -04:00
Compare commits
5 Commits
8e22094359
...
e6a983e5f0
Author | SHA1 | Date | |
---|---|---|---|
e6a983e5f0 | |||
97ea67198b | |||
27a70e4c12 | |||
aeb0cad979 | |||
fd38dd116f |
@ -1,4 +1,9 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
scrollToActiveItem();
|
||||||
|
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) {
|
||||||
button.addEventListener("click", function (e) {
|
button.addEventListener("click", function (e) {
|
||||||
@ -9,4 +14,23 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -1,4 +1,26 @@
|
|||||||
{{- $lang := site.Language.LanguageCode | default `en` -}}
|
{{ $default_chinese := "zh-CN" }}
|
||||||
|
|
||||||
|
{{ $sl := site.Language }}
|
||||||
|
{{ $giscus_lang := $sl.Lang | default `en` }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Special case for Chinese.
|
||||||
|
Giscus uses the geophraphical language code for these.
|
||||||
|
See: https://github.com/giscus/giscus/tree/main/locales
|
||||||
|
*/}}
|
||||||
|
{{ if eq $giscus_lang "zh" }}
|
||||||
|
{{/* Create a code formatted for Giscus: zh-CN or zn-TW. */}}
|
||||||
|
{{ $code := lower $sl.LanguageCode }}
|
||||||
|
|
||||||
|
{{ if (hasSuffix $code "-cn") }}
|
||||||
|
{{ $giscus_lang = "zh-CN" }}
|
||||||
|
{{ else if (hasSuffix $code "-tw") }}
|
||||||
|
{{ $giscus_lang = "zh-TW" }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $giscus_lang = $default_chinese }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
{{- with site.Params.comments.giscus -}}
|
{{- with site.Params.comments.giscus -}}
|
||||||
<script>
|
<script>
|
||||||
@ -38,7 +60,7 @@
|
|||||||
"data-emit-metadata": "{{ (string .emitMetadata) | default 0 }}",
|
"data-emit-metadata": "{{ (string .emitMetadata) | default 0 }}",
|
||||||
"data-input-position": "{{ .inputPosition | default `top` }}",
|
"data-input-position": "{{ .inputPosition | default `top` }}",
|
||||||
"data-theme": getGiscusTheme(),
|
"data-theme": getGiscusTheme(),
|
||||||
"data-lang": "{{ .lang | default $lang }}",
|
"data-lang": "{{ .lang | default $giscus_lang }}",
|
||||||
"crossorigin": "anonymous",
|
"crossorigin": "anonymous",
|
||||||
"async": "",
|
"async": "",
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user