mirror of
https://github.com/discourse/DiscoTOC.git
synced 2025-02-16 08:24:49 +00:00
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";
|
||||
const headings = el.querySelectorAll(dTocHeadingSelectors);
|
||||
|
||||
if (headings.length < 1) {
|
||||
if (headings.length < settings.TOC_min_heading) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,3 +20,7 @@ auto_TOC_tags:
|
||||
type: list
|
||||
list_type: tag
|
||||
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) {
|
||||
needs.pretender((server, helper) => {
|
||||
settings.TOC_min_heading = 1;
|
||||
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
|
||||
topicResponse.post_stream.posts[0].cooked = `
|
||||
<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…
x
Reference in New Issue
Block a user