DEV: Remove superfluous `toc` and `TOC` terms in site settings

This commit is contained in:
Alan Guo Xiang Tan 2024-01-11 13:47:34 +08:00
parent 3179e886a3
commit 8e9a175e16
No known key found for this signature in database
GPG Key ID: 3F656E28E3AADEF1
9 changed files with 84 additions and 19 deletions

View File

@ -224,7 +224,7 @@ a.d-toc-close {
align-items: center;
justify-content: center;
&:before {
content: "#{$composer_toc_text}";
content: "#{$composer_text}";
}
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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 按钮的最低信任等级

View File

@ -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;
}

View File

@ -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

View File

@ -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 = `
<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) {
});
});
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' +

View File

@ -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,
})
)
)
);
});
});