[new option] tocLevels

Sometimes, toc doen't work correctly. This option fixes the issue.
This commit is contained in:
zzossig 2020-02-13 11:11:33 +09:00
parent 5a42616dc9
commit a447d1561c
5 changed files with 19 additions and 7 deletions

View File

@ -285,6 +285,7 @@ tocFolding = false
enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar.
sidebarPosition = "right" # bio, profile component layout position
tocLevels = ["h2", "h3", "h4"] # minimum h2, maximum h4 in your article
# footer
showPoweredBy = true # show footer text: Powered by Hugo and Zzo theme

View File

@ -293,6 +293,7 @@ tocFolding = false
enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar.
sidebarPosition = "right" # bio, profile component layout position
tocLevels = ["h2", "h3", "h4"] # minimum h2, maximum h4 in your article
# footer
showPoweredBy = true # show footer text: Powered by Hugo and Zzo theme

View File

@ -7,6 +7,7 @@ hideToc: false
enableToc: true
enableTocContent: false
tocPosition: inner
tocLevels: ["h2", "h3", "h4"]
tags:
-
series:

View File

@ -55,6 +55,7 @@ tocPosition = "inner" # inner, outer
enableTocSwitch = true
itemsPerCategory = 5
sidebarPosition = "right"
tocLevels = ["h2", "h3", "h4"]
# footer
showPoweredBy = true

View File

@ -214,11 +214,19 @@
{{ $tocFolding := $.Param "tocFolding" }}
var tocFolding = JSON.parse({{ $tocFolding | jsonify }});
{{ $tocLevels := ($.Param "tocLevels") }}
var tocLevels = JSON.parse({{ $tocLevels | jsonify }});
if (tocLevels) {
tocLevels = tocLevels.toString();
} else {
tocLevels = "h1, h2, h3, h4, h5, h6";
}
// tab
singleContentsElem && singleContentsElem.querySelectorAll(".tab") ?
singleContentsElem.querySelectorAll(".tab").forEach(function (elem) {
elem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (element) {
elem.querySelectorAll(tocLevels).forEach(function (element) {
notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
notAllowedTitleIds.concat(element.getAttribute('id')) :
[element.getAttribute('id')];
@ -227,7 +235,7 @@
// expand
expandContents ? expandContents.forEach(function(elem) {
elem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (element) {
elem.querySelectorAll(tocLevels).forEach(function (element) {
notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
notAllowedTitleIds.concat(element.getAttribute('id')) :
[element.getAttribute('id')];
@ -236,7 +244,7 @@
// box
boxContents ? boxContents.forEach(function(elem) {
elem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (element) {
elem.querySelectorAll(tocLevels).forEach(function (element) {
notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
notAllowedTitleIds.concat(element.getAttribute('id')) :
[element.getAttribute('id')];
@ -266,8 +274,8 @@
}
if (singleContentsElem) {
if (singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").length > 0) {
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (elem) {
if (singleContentsElem.querySelectorAll(tocLevels).length > 0) {
singleContentsElem.querySelectorAll(tocLevels).forEach(function (elem) {
if (toggleTocElem && !toggleTocElem.checked) {
return null;
}
@ -336,8 +344,8 @@
}
if (singleContentsElem) {
if (singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").length > 0) {
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (elem) {
if (singleContentsElem.querySelectorAll(tocLevels).length > 0) {
singleContentsElem.querySelectorAll(tocLevels).forEach(function (elem) {
if (toggleTocElem && !toggleTocElem.checked) {
return null;
}