Skip to content

Commit 8e9a175

Browse files
committed
DEV: Remove superfluous toc and TOC terms in site settings
1 parent 3179e88 commit 8e9a175

File tree

9 files changed

+84
-19
lines changed

9 files changed

+84
-19
lines changed

common/common.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ a.d-toc-close {
224224
align-items: center;
225225
justify-content: center;
226226
&:before {
227-
content: "#{$composer_toc_text}";
227+
content: "#{$composer_text}";
228228
}
229229
}
230230

javascripts/discourse/initializers/disco-toc-composer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
return;
1212
}
1313

14-
const minimumTL = settings.minimum_trust_level_to_create_TOC;
14+
const minimumTL = settings.minimum_trust_level_to_create;
1515

1616
if (currentUser.trust_level >= minimumTL) {
1717
if (!I18n.translations[I18n.currentLocale()].js.composer) {

javascripts/discourse/initializers/disco-toc-main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export default {
1111

1212
initialize() {
1313
withPluginApi("1.0.0", (api) => {
14-
const autoTocCategoryIds = settings.auto_TOC_categories
14+
const autoTocCategoryIds = settings.auto_categories
1515
.split("|")
1616
.map((id) => parseInt(id, 10));
1717

18-
const autoTocTags = settings.auto_TOC_tags.split("|");
18+
const autoTocTags = settings.auto_tags.split("|");
1919

2020
api.decorateCookedElement(
2121
(el, helper) => {
@@ -41,7 +41,7 @@ export default {
4141
":scope > h1, :scope > h2, :scope > h3, :scope > h4, :scope > h5";
4242
const headings = el.querySelectorAll(dTocHeadingSelectors);
4343

44-
if (headings.length < settings.TOC_min_heading) {
44+
if (headings.length < settings.min_heading) {
4545
return;
4646
}
4747

locales/en.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ en:
44
post_bottom_tooltip: Navigate to post controls
55
theme_metadata:
66
settings:
7-
minimum_trust_level_to_create_TOC: The minimum trust level a user must have in order to see the TOC button in the composer
8-
auto_TOC_categories: automatically enable TOC on topics in these categories
9-
auto_TOC_tags: automatically enable TOC on topics with these tags
7+
minimum_trust_level_to_create: The minimum trust level a user must have in order to see the TOC button in the composer
8+
auto_categories: automatically enable TOC on topics in these categories
9+
auto_tags: automatically enable TOC on topics with these tags

locales/zh_CN.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ zh_CN:
44
post_bottom_tooltip: 帖子控制
55
theme_metadata:
66
settings:
7-
minimum_trust_level_to_create_TOC: 能够在编辑器中显示 TOC 按钮的最低信任等级
7+
minimum_trust_level_to_create: 能够在编辑器中显示 TOC 按钮的最低信任等级
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export default function migrate(settings) {
2+
if (settings.has("minimum_trust_level_to_create_TOC")) {
3+
settings.set(
4+
"minimum_trust_level_to_create",
5+
settings.get("minimum_trust_level_to_create_TOC")
6+
);
7+
8+
settings.delete("minimum_trust_level_to_create_TOC");
9+
}
10+
11+
if (settings.has("composer_toc_text")) {
12+
settings.set("composer_text", settings.get("composer_toc_text"));
13+
settings.delete("composer_toc_text");
14+
}
15+
16+
if (settings.has("auto_TOC_categories")) {
17+
settings.set("auto_categories", settings.get("auto_TOC_categories"));
18+
settings.delete("auto_TOC_categories");
19+
}
20+
21+
if (settings.has("auto_TOC_tags")) {
22+
settings.set("auto_tags", settings.get("auto_TOC_tags"));
23+
settings.delete("auto_TOC_tags");
24+
}
25+
26+
if (settings.has("TOC_min_heading")) {
27+
settings.set("min_heading", settings.get("TOC_min_heading"));
28+
settings.delete("TOC_min_heading");
29+
}
30+
31+
return settings;
32+
}

settings.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
minimum_trust_level_to_create_TOC:
1+
minimum_trust_level_to_create:
22
default: 0
33
type: enum
44
choices:
55
- 1
66
- 2
77
- 3
88
- 4
9-
composer_toc_text:
9+
composer_text:
1010
default: "This topic will contain a table of contents"
1111
table_of_contents_icon:
1212
default: "align-left"
1313
anchor_icon:
1414
default: "hashtag"
15-
auto_TOC_categories:
15+
auto_categories:
1616
type: list
1717
list_type: category
1818
default: ""
19-
auto_TOC_tags:
19+
auto_tags:
2020
type: list
2121
list_type: tag
2222
default: ""
23-
TOC_min_heading:
23+
min_heading:
2424
default: 3
2525
min: 1
2626
max: 10000

test/acceptance/toc-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ acceptance("DiscoTOC - off", function (needs) {
8787

8888
acceptance("DiscoTOC - with tags", function (needs) {
8989
needs.pretender((server, helper) => {
90-
settings.auto_TOC_tags = TOC_AUTO_TAGS;
90+
settings.auto_tags = TOC_AUTO_TAGS;
9191
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
9292
topicResponse.post_stream.posts[0].cooked = COOKED_WITH_HEADINGS;
9393
topicResponse.tags = TOC_TOPIC_TAGS;
@@ -106,7 +106,7 @@ acceptance("DiscoTOC - with tags", function (needs) {
106106

107107
acceptance("DiscoTOC - with categories", function (needs) {
108108
needs.pretender((server, helper) => {
109-
settings.auto_TOC_categories = TOC_AUTO_CATEGORIES;
109+
settings.auto_categories = TOC_AUTO_CATEGORIES;
110110
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
111111
topicResponse.post_stream.posts[0].cooked = COOKED_WITH_HEADINGS;
112112
topicResponse.category_id = TOC_TOPIC_CATEGORY;
@@ -125,7 +125,7 @@ acceptance("DiscoTOC - with categories", function (needs) {
125125

126126
acceptance("DiscoTOC - non-text headings", function (needs) {
127127
needs.pretender((server, helper) => {
128-
settings.TOC_min_heading = 1;
128+
settings.min_heading = 1;
129129
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
130130
topicResponse.post_stream.posts[0].cooked = `
131131
<h3 id="toc-h3-span" data-d-toc="toc-h3-span" class="d-toc-post-heading">
@@ -152,9 +152,9 @@ acceptance("DiscoTOC - non-text headings", function (needs) {
152152
});
153153
});
154154

155-
acceptance("DiscoTOC - setting TOC_min_heading", function (needs) {
155+
acceptance("DiscoTOC - setting min_heading", function (needs) {
156156
needs.pretender((server, helper) => {
157-
settings.TOC_min_heading = 3;
157+
settings.min_heading = 3;
158158
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
159159
topicResponse.post_stream.posts[0].cooked =
160160
'<h1>\n<a name="h1-first-test-edited-1" class="anchor" href="#h1-first-test-edited-1"></a>帖子控制</h1>\nWelcome' +
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { module, test } from "qunit";
2+
import migrate from "../../../../migrations/settings/0001-rename-settings";
3+
4+
module("Unit | Migrations | Settings | 0001-rename-settings", function () {
5+
test("migrate", function (assert) {
6+
const settings = new Map(
7+
Object.entries({
8+
minimum_trust_level_to_create_TOC: 0,
9+
composer_toc_text: "some text",
10+
auto_TOC_categories: "1|2",
11+
auto_TOC_tags: "tag1|tag2",
12+
TOC_min_heading: 3,
13+
})
14+
);
15+
16+
const result = migrate(settings);
17+
18+
assert.deepEqual(
19+
Array.from(result),
20+
Array.from(
21+
new Map(
22+
Object.entries({
23+
minimum_trust_level_to_create: 0,
24+
composer_text: "some text",
25+
auto_categories: "1|2",
26+
auto_tags: "tag1|tag2",
27+
min_heading: 3,
28+
})
29+
)
30+
)
31+
);
32+
});
33+
});

0 commit comments

Comments
 (0)