Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ a.d-toc-close {
align-items: center;
justify-content: center;
&:before {
content: "#{$composer_toc_text}";
content: "#{$composer_text}";
}
}

Expand Down
2 changes: 1 addition & 1 deletion javascripts/discourse/initializers/disco-toc-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
return;
}

const minimumTL = settings.minimum_trust_level_to_create_TOC;
const minimumTL = settings.minimum_trust_level_to_create;

if (currentUser.trust_level >= minimumTL) {
if (!I18n.translations[I18n.currentLocale()].js.composer) {
Expand Down
6 changes: 3 additions & 3 deletions javascripts/discourse/initializers/disco-toc-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default {

initialize() {
withPluginApi("1.0.0", (api) => {
const autoTocCategoryIds = settings.auto_TOC_categories
const autoTocCategoryIds = settings.auto_categories
.split("|")
.map((id) => parseInt(id, 10));

const autoTocTags = settings.auto_TOC_tags.split("|");
const autoTocTags = settings.auto_tags.split("|");

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

if (headings.length < settings.TOC_min_heading) {
if (headings.length < settings.min_heading) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ en:
post_bottom_tooltip: Navigate to post controls
theme_metadata:
settings:
minimum_trust_level_to_create_TOC: The minimum trust level a user must have in order to see the TOC button in the composer
auto_TOC_categories: automatically enable TOC on topics in these categories
auto_TOC_tags: automatically enable TOC on topics with these tags
minimum_trust_level_to_create: The minimum trust level a user must have in order to see the TOC button in the composer
auto_categories: automatically enable TOC on topics in these categories
auto_tags: automatically enable TOC on topics with these tags
2 changes: 1 addition & 1 deletion locales/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ zh_CN:
post_bottom_tooltip: 帖子控制
theme_metadata:
settings:
minimum_trust_level_to_create_TOC: 能够在编辑器中显示 TOC 按钮的最低信任等级
minimum_trust_level_to_create: 能够在编辑器中显示 TOC 按钮的最低信任等级
32 changes: 32 additions & 0 deletions migrations/settings/0001-rename-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default function migrate(settings) {
if (settings.has("minimum_trust_level_to_create_TOC")) {
settings.set(
"minimum_trust_level_to_create",
settings.get("minimum_trust_level_to_create_TOC")
);

settings.delete("minimum_trust_level_to_create_TOC");
}

if (settings.has("composer_toc_text")) {
settings.set("composer_text", settings.get("composer_toc_text"));
settings.delete("composer_toc_text");
}

if (settings.has("auto_TOC_categories")) {
settings.set("auto_categories", settings.get("auto_TOC_categories"));
settings.delete("auto_TOC_categories");
}

if (settings.has("auto_TOC_tags")) {
settings.set("auto_tags", settings.get("auto_TOC_tags"));
settings.delete("auto_TOC_tags");
}

if (settings.has("TOC_min_heading")) {
settings.set("min_heading", settings.get("TOC_min_heading"));
settings.delete("TOC_min_heading");
}

return settings;
}
10 changes: 5 additions & 5 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
minimum_trust_level_to_create_TOC:
minimum_trust_level_to_create:
default: 0
type: enum
choices:
- 1
- 2
- 3
- 4
composer_toc_text:
composer_text:
default: "This topic will contain a table of contents"
table_of_contents_icon:
default: "align-left"
anchor_icon:
default: "hashtag"
auto_TOC_categories:
auto_categories:
type: list
list_type: category
default: ""
auto_TOC_tags:
auto_tags:
type: list
list_type: tag
default: ""
TOC_min_heading:
min_heading:
default: 3
min: 1
max: 10000
10 changes: 5 additions & 5 deletions test/acceptance/toc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ acceptance("DiscoTOC - off", function (needs) {

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

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

acceptance("DiscoTOC - non-text headings", function (needs) {
needs.pretender((server, helper) => {
settings.TOC_min_heading = 1;
settings.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">
Expand All @@ -152,9 +152,9 @@ acceptance("DiscoTOC - non-text headings", function (needs) {
});
});

acceptance("DiscoTOC - setting TOC_min_heading", function (needs) {
acceptance("DiscoTOC - setting min_heading", function (needs) {
needs.pretender((server, helper) => {
settings.TOC_min_heading = 3;
settings.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' +
Expand Down
33 changes: 33 additions & 0 deletions test/unit/migrations/settings/0001-rename-settings-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { module, test } from "qunit";
import migrate from "../../../../migrations/settings/0001-rename-settings";

module("Unit | Migrations | Settings | 0001-rename-settings", function () {
test("migrate", function (assert) {
const settings = new Map(
Object.entries({
minimum_trust_level_to_create_TOC: 0,
composer_toc_text: "some text",
auto_TOC_categories: "1|2",
auto_TOC_tags: "tag1|tag2",
TOC_min_heading: 3,
})
);

const result = migrate(settings);

assert.deepEqual(
Array.from(result),
Array.from(
new Map(
Object.entries({
minimum_trust_level_to_create: 0,
composer_text: "some text",
auto_categories: "1|2",
auto_tags: "tag1|tag2",
min_heading: 3,
})
)
)
);
});
});