FEATURE: new theme setting to disable TOC in posts with less headings. (#47)
The theme setting `TOC_min_heading` will decide whether the TOC should display or not based on the number of headings available in the post.
This commit is contained in:
parent
1d3b28355c
commit
55f83a913c
|
@ -41,7 +41,7 @@ export default {
|
||||||
":scope > h1, :scope > h2, :scope > h3, :scope > h4, :scope > h5";
|
":scope > h1, :scope > h2, :scope > h3, :scope > h4, :scope > h5";
|
||||||
const headings = el.querySelectorAll(dTocHeadingSelectors);
|
const headings = el.querySelectorAll(dTocHeadingSelectors);
|
||||||
|
|
||||||
if (headings.length < 1) {
|
if (headings.length < settings.TOC_min_heading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,7 @@ auto_TOC_tags:
|
||||||
type: list
|
type: list
|
||||||
list_type: tag
|
list_type: tag
|
||||||
default: ""
|
default: ""
|
||||||
|
TOC_min_heading:
|
||||||
|
default: 3
|
||||||
|
min: 1
|
||||||
|
max: 10000
|
||||||
|
|
|
@ -125,6 +125,7 @@ acceptance("DiscoTOC - with categories", function (needs) {
|
||||||
|
|
||||||
acceptance("DiscoTOC - non-text headings", function (needs) {
|
acceptance("DiscoTOC - non-text headings", function (needs) {
|
||||||
needs.pretender((server, helper) => {
|
needs.pretender((server, helper) => {
|
||||||
|
settings.TOC_min_heading = 1;
|
||||||
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
|
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
|
||||||
topicResponse.post_stream.posts[0].cooked = `
|
topicResponse.post_stream.posts[0].cooked = `
|
||||||
<h3 id="toc-h3-span" data-d-toc="toc-h3-span" class="d-toc-post-heading">
|
<h3 id="toc-h3-span" data-d-toc="toc-h3-span" class="d-toc-post-heading">
|
||||||
|
@ -150,3 +151,27 @@ acceptance("DiscoTOC - non-text headings", function (needs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("DiscoTOC - setting TOC_min_heading", function (needs) {
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
settings.TOC_min_heading = 3;
|
||||||
|
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
|
||||||
|
topicResponse.post_stream.posts[0].cooked =
|
||||||
|
'<h1>\n<a name="h1-first-test-edited-1" class="anchor" href="#h1-first-test-edited-1"></a>帖子控制</h1>\nWelcome' +
|
||||||
|
TOC_MARKUP;
|
||||||
|
|
||||||
|
server.get("/t/280.json", () => helper.response(topicResponse));
|
||||||
|
server.get("/t/280/:post_number.json", () =>
|
||||||
|
helper.response(topicResponse)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("hiding TOC element", async function (assert) {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(".d-toc-timeline-visible .d-toc-main"),
|
||||||
|
"TOC element not visible"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue