fix: preserve article sidebar when TOC is empty

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