diff --git a/common/common.scss b/common/common.scss index 55e8502..ad43d00 100644 --- a/common/common.scss +++ b/common/common.scss @@ -224,7 +224,7 @@ a.d-toc-close { align-items: center; justify-content: center; &:before { - content: "#{$composer_toc_text}"; + content: "#{$composer_text}"; } } diff --git a/javascripts/discourse/initializers/disco-toc-composer.js b/javascripts/discourse/initializers/disco-toc-composer.js index 6435dc6..fdc95c3 100644 --- a/javascripts/discourse/initializers/disco-toc-composer.js +++ b/javascripts/discourse/initializers/disco-toc-composer.js @@ -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) { diff --git a/javascripts/discourse/initializers/disco-toc-main.js b/javascripts/discourse/initializers/disco-toc-main.js index f88561e..950551f 100644 --- a/javascripts/discourse/initializers/disco-toc-main.js +++ b/javascripts/discourse/initializers/disco-toc-main.js @@ -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) => { @@ -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; } diff --git a/locales/en.yml b/locales/en.yml index 7b587ec..cbcbaf5 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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 diff --git a/locales/zh_CN.yml b/locales/zh_CN.yml index a574042..bfe5c64 100644 --- a/locales/zh_CN.yml +++ b/locales/zh_CN.yml @@ -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 按钮的最低信任等级 diff --git a/migrations/settings/0001-rename-settings.js b/migrations/settings/0001-rename-settings.js new file mode 100644 index 0000000..01a64f1 --- /dev/null +++ b/migrations/settings/0001-rename-settings.js @@ -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; +} diff --git a/settings.yml b/settings.yml index 2374341..89456c4 100644 --- a/settings.yml +++ b/settings.yml @@ -1,4 +1,4 @@ -minimum_trust_level_to_create_TOC: +minimum_trust_level_to_create: default: 0 type: enum choices: @@ -6,21 +6,21 @@ minimum_trust_level_to_create_TOC: - 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 diff --git a/test/acceptance/toc-test.js b/test/acceptance/toc-test.js index bf34a6b..35eb702 100644 --- a/test/acceptance/toc-test.js +++ b/test/acceptance/toc-test.js @@ -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; @@ -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; @@ -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 = `