diff --git a/README.ko.md b/README.ko.md index 7dbb980..280776a 100644 --- a/README.ko.md +++ b/README.ko.md @@ -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 diff --git a/README.md b/README.md index 14a0397..6082c46 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/archetypes/default.md b/archetypes/default.md index f581553..e082fd7 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -7,6 +7,7 @@ hideToc: false enableToc: true enableTocContent: false tocPosition: inner +tocLevels: ["h2", "h3", "h4"] tags: - series: diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 9391f7b..1b6f348 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -55,6 +55,7 @@ tocPosition = "inner" # inner, outer enableTocSwitch = true itemsPerCategory = 5 sidebarPosition = "right" +tocLevels = ["h2", "h3", "h4"] # footer showPoweredBy = true diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html index 3a5f403..1e81e67 100644 --- a/layouts/partials/head/scripts.html +++ b/layouts/partials/head/scripts.html @@ -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; }