fix: preserve article sidebar when TOC is empty

This commit is contained in:
kate522 committed 2026-08-14 13:49:56 +08:00
1 parent 151cb642fa
commit df7ca8a739
1 file changed
+5 -4
+5 -4
View File
@@ -111,10 +111,11 @@
if (!hasToc) { if (!hasToc) {
tocWidgets.forEach(function (box) { tocWidgets.forEach(function (box) {
var host = box.closest('.widget') || box.parentElement; var widget = box.closest('.widget');
// Prefer removing the whole widget chrome when empty. // A built-in TOC is a direct child of the article sidebar. Its parent
if (host && host !== document.body && host.querySelectorAll('.posts-nav-box').length <= 1) { // is therefore not widget chrome and must never be removed here.
host.remove(); if (widget && widget !== document.body && widget.querySelectorAll('.posts-nav-box').length <= 1) {
widget.remove();
} else { } else {
box.remove(); box.remove();
} }