98 | content.includes(tag)
99 | );
100 | }
101 |
102 | populateTocData(postId, content, headings) {
103 | this.hasTOC = true;
104 | this.postID = postId;
105 | this.postContent = content;
106 | this.tocStructure = this.generateTocStructure(headings);
107 | }
108 |
109 | autoTOC(topic) {
110 | // check topic for categories or tags from settings
111 | const autoCategories = settings.auto_TOC_categories
112 | ? settings.auto_TOC_categories.split("|").map((id) => parseInt(id, 10))
113 | : [];
114 |
115 | const autoTags = settings.auto_TOC_tags
116 | ? settings.auto_TOC_tags.split("|")
117 | : [];
118 |
119 | if ((!autoCategories.length && !autoTags.length) || !topic) {
120 | return false;
121 | }
122 |
123 | const topicCategory = topic.category_id;
124 | const topicTags = topic.tags || [];
125 |
126 | const hasMatchingTags = autoTags.some((tag) => topicTags.includes(tag));
127 | const hasMatchingCategory = autoCategories.includes(topicCategory);
128 |
129 | // only apply autoTOC on first post
130 | // the docs plugin only shows the first post, and does not have topic.currentPost defined
131 | return (
132 | (hasMatchingTags || hasMatchingCategory) &&
133 | (topic.currentPost === 1 || topic.currentPost === undefined)
134 | );
135 | }
136 |
137 | /**
138 | * @param {number} postId
139 | * @param {HTMLHeadingElement} heading
140 | * @param {Map} sameIdCount
141 | */
142 | getIdFromHeading(postId, heading, sameIdCount) {
143 | const anchor = heading.querySelector("a.anchor");
144 | if (anchor) {
145 | return anchor.name;
146 | }
147 | const lowerTagName = heading.tagName.toLowerCase();
148 | const text = heading.textContent.trim();
149 | let slug = `${slugify(text)}`;
150 | if (sameIdCount.has(slug)) {
151 | sameIdCount.set(slug, sameIdCount.get(slug) + 1);
152 | slug = `${slug}-${sameIdCount.get(slug)}`;
153 | } else {
154 | sameIdCount.set(slug, 1);
155 | }
156 | const res = `p-${postId}-toc-${lowerTagName}-${slug}`;
157 | heading.id = res;
158 | return res;
159 | }
160 |
161 | generateTocStructure(headings) {
162 | let root = { subItems: [], level: 0 };
163 | let ancestors = [root];
164 |
165 | const sameIdCount = new Map();
166 |
167 | headings.forEach((heading) => {
168 | const level = parseInt(heading.tagName[1], 10);
169 | const text = heading.textContent.trim();
170 | const lowerTagName = heading.tagName.toLowerCase();
171 |
172 | const id = this.getIdFromHeading(this.postID, heading, sameIdCount);
173 |
174 | // Remove irrelevant ancestors
175 | while (ancestors[ancestors.length - 1].level >= level) {
176 | ancestors.pop();
177 | }
178 |
179 | let headingData = {
180 | id,
181 | tagName: lowerTagName,
182 | text,
183 | subItems: [],
184 | level,
185 | parent: ancestors.length > 1 ? ancestors[ancestors.length - 1] : null,
186 | };
187 |
188 | ancestors[ancestors.length - 1].subItems.push(headingData);
189 | ancestors.push(headingData);
190 | });
191 |
192 | return root.subItems;
193 | }
194 |
195 | jumpToEnd(renderTimeline, postID) {
196 | let buffer = 150;
197 | const postContainer = document.querySelector(`[data-post-id="${postID}"]`);
198 |
199 | if (!renderTimeline) {
200 | this.setOverlayVisible(false);
201 | }
202 |
203 | if (postContainer) {
204 | // if the topic map is present, we don't want to scroll past it
205 | // so the post controls are still visible
206 | const topicMapHeight =
207 | postContainer.querySelector(`.topic-map`)?.offsetHeight || 0;
208 |
209 | if (
210 | postContainer.parentElement?.nextElementSibling?.querySelector(
211 | "div[data-theme-toc]"
212 | )
213 | ) {
214 | // but if the next post also has a toc, just jump to it
215 | buffer = 30 - topicMapHeight;
216 | }
217 |
218 | const offsetPosition =
219 | postContainer.getBoundingClientRect().bottom +
220 | window.scrollY -
221 | buffer -
222 | topicMapHeight;
223 |
224 | window.scrollTo({ top: offsetPosition, behavior: "smooth" });
225 | }
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/locales/ar.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ar:
8 | table_of_contents: جدول المحتويات
9 | insert_table_of_contents: إدراج جدول محتويات
10 | jump_bottom: الانتقال إلى النهاية
11 | toggle_toc:
12 | show_timeline: الخط الزمني
13 | show_toc: المحتويات
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: الحد الأدنى لمستوى الثقة الذي يجب أن يكون لدى المستخدم من أجل رؤية زر جدول المحتويات في أداة الإنشاء
17 | composer_toc_text: النص الذي يظهر في أعلى لوحة المعاينة في أداة الأنشاء للإشارة إلى أن الموضوع سيتضمن جدول محتويات
18 | auto_TOC_categories: تفعيل جدول المحتويات تلقائيًا في الموضوعات الموجودة في هذه الفئات
19 | auto_TOC_tags: تفعيل جدول المحتويات تلقائيًا في الموضوعات التي تحتوي على هذه الوسوم
20 | TOC_min_heading: الحد الأدنى لعدد العناوين في الموضوع ليتم عرض جدول المحتويات
21 | enable_TOC_for_replies: يسمح بجدول محتويات للردود. لا تتأثر جداول المحتويات للردود بإعدادات وسوم جدول المحتويات التلقائية وفئات جدول المحتويات التلقائية ويجب إدراجها يدويًا.
22 |
--------------------------------------------------------------------------------
/locales/be.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | be:
8 |
--------------------------------------------------------------------------------
/locales/bg.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | bg:
8 |
--------------------------------------------------------------------------------
/locales/bs_BA.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | bs_BA:
8 |
--------------------------------------------------------------------------------
/locales/ca.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ca:
8 |
--------------------------------------------------------------------------------
/locales/cs.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | cs:
8 | table_of_contents: obsah
9 | insert_table_of_contents: Vložit obsah
10 | jump_bottom: Přeskočit na konec
11 | toggle_toc:
12 | show_timeline: Časová osa
13 | show_toc: Obsah
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Minimální úroveň důvěry, kterou musí mít uživatel, aby se v editoru zobrazilo tlačítko Obsah
17 | auto_TOC_categories: Automaticky povolit obsah pro témata v těchto kategoriích
18 | auto_TOC_tags: Automaticky povolit TOC u témat s těmito štítky
19 |
--------------------------------------------------------------------------------
/locales/da.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | da:
8 |
--------------------------------------------------------------------------------
/locales/de.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | de:
8 | table_of_contents: Inhaltsverzeichnis
9 | insert_table_of_contents: Inhaltsverzeichnis einfügen
10 | jump_bottom: Zum Ende springen
11 | toggle_toc:
12 | show_timeline: Zeitleiste
13 | show_toc: Inhalt
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Die minimale Vertrauensstufe, die ein Benutzer haben muss, um die Schaltfläche „Inhaltsverzeichnis“ im Editor zu sehen
17 | composer_toc_text: Text, der oben im Vorschaufenster des Editors erscheint und darauf hinweist, dass das Thema ein Inhaltsverzeichnis haben wird
18 | auto_TOC_categories: Automatisches Aktivieren des Inhaltsverzeichnisses für Themen in diesen Kategorien
19 | auto_TOC_tags: Automatisches Aktivieren des Inhaltsverzeichnisses für Themen mit diesen Schlagwörtern
20 | TOC_min_heading: Mindestanzahl von Überschriften in einem Thema, damit das Inhaltsverzeichnis angezeigt wird
21 | enable_TOC_for_replies: Erlaube Inhaltsverzeichnisse für Antworten. Inhaltsverzeichnisse für Antworten werden von den Einstellungen auto TOC tags und auto TOC categories nicht beeinflusst, sondern müssen manuell eingefügt werden.
22 |
--------------------------------------------------------------------------------
/locales/el.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | el:
8 |
--------------------------------------------------------------------------------
/locales/en.yml:
--------------------------------------------------------------------------------
1 | en:
2 | table_of_contents: table of contents
3 | insert_table_of_contents: Insert table of contents
4 | jump_bottom: Jump to end
5 | toggle_toc:
6 | show_timeline: Timeline
7 | show_toc: Contents
8 | theme_metadata:
9 | settings:
10 | minimum_trust_level_to_create_TOC: The minimum trust level a user must have in order to see the TOC button in the composer
11 | composer_toc_text: Text that appears at the top of the preview pane of the composer to indicate the topic will have a table of contents
12 | auto_TOC_categories: Automatically enable TOC on topics in these categories
13 | auto_TOC_tags: Automatically enable TOC on topics with these tags
14 | TOC_min_heading: Minimum number of headings in a topic for the table of contents to be shown
15 | enable_TOC_for_replies: Allows TOC for replies. TOCs for replies are not affected by the auto TOC tags and auto TOC categories settings and must be inserted manually.
16 |
--------------------------------------------------------------------------------
/locales/en_GB.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | en_GB:
8 |
--------------------------------------------------------------------------------
/locales/es.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | es:
8 | table_of_contents: tabla de contenidos
9 | insert_table_of_contents: Insertar tabla de contenido
10 | jump_bottom: Saltar al final
11 | toggle_toc:
12 | show_timeline: Línea de tiempo
13 | show_toc: Contenido
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: El nivel de confianza mínimo que debe tener un usuario para ver el botón TOC en el compositor
17 | composer_toc_text: El texto que aparezca en la parte superior del panel de vista previa del compositor para indicar el tema tendrá una tabla de contenido
18 | auto_TOC_categories: Activar automáticamente TOC en temas de estas categorías
19 | auto_TOC_tags: Activar automáticamente TOC en temas con estas etiquetas
20 | TOC_min_heading: Número mínimo de encabezados en un tema para que se muestre la tabla de contenido
21 | enable_TOC_for_replies: Permite que TOC responda. Las TOC para las respuestas no se ven afectadas por los ajustes de las etiquetas de TOC automático y categorías de TOC automático y se deben insertar manualmente.
22 |
--------------------------------------------------------------------------------
/locales/et.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | et:
8 |
--------------------------------------------------------------------------------
/locales/fa_IR.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | fa_IR:
8 | table_of_contents: فهرست مطالب
9 | insert_table_of_contents: فهرست مطالب را وارد کنید
10 | jump_bottom: پرش به انتها
11 |
--------------------------------------------------------------------------------
/locales/fi.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | fi:
8 | table_of_contents: sisällysluettelo
9 | insert_table_of_contents: Lisää sisällysluettelo
10 | jump_bottom: Siirry loppuun
11 | toggle_toc:
12 | show_timeline: Aikajana
13 | show_toc: Sisältö
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Vähimmäisluottamustaso, joka käyttäjällä täytyy olla, jotta hän näkee sisällysluettelopainikkeen tekstieditorissa
17 | composer_toc_text: Teksti, joka näkyy tekstieditorin esikatseluruudun yläosassa ja ilmaisee, että ketjulla on sisällysluettelo
18 | auto_TOC_categories: Ota sisällysluettelo automaattisesti käyttöön näiden alueiden ketjuissa
19 | auto_TOC_tags: Ota sisällysluettelo automaattisesti käyttöön ketjuissa, joilla on näitä tunnisteita
20 | TOC_min_heading: Ketjun otsikoiden vähimmäismäärä, jotta sisällysluettelo näytetään
21 | enable_TOC_for_replies: Sallii sisällysluettelo vastauksissa. Automaattisten sisällysluettelotunnisteiden ja automaattisten sisällysluetteloalueiden asetukset eivät vaikuta vastausten sisällysluetteloihin, ja ne on lisättävä manuaalisesti.
22 |
--------------------------------------------------------------------------------
/locales/fr.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | fr:
8 | table_of_contents: table des matières
9 | insert_table_of_contents: Insérer une table des matières
10 | jump_bottom: Accéder à la fin
11 | toggle_toc:
12 | show_timeline: Chronologie
13 | show_toc: Sommaire
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Le niveau de confiance minimum qu'un utilisateur doit avoir pour voir le bouton de la table des matières dans le compositeur
17 | composer_toc_text: Le texte qui apparaît en haut du volet d'aperçu du compositeur pour indiquer que le sujet comportera une table des matières
18 | auto_TOC_categories: Activer automatiquement la table des matières sur les sujets de ces catégories
19 | auto_TOC_tags: Activer automatiquement la table des matières sur les sujets avec ces étiquettes
20 | TOC_min_heading: Nombre minimum de titres dans un sujet pour que la table des matières soit affichée
21 | enable_TOC_for_replies: Autorise la table des matières pour les réponses. Les tables des matières pour les réponses ne sont pas affectées par les paramètres des étiquettes de table des matières automatiques et des catégories de table des matières automatiques et doivent être insérées manuellement.
22 |
--------------------------------------------------------------------------------
/locales/gl.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | gl:
8 |
--------------------------------------------------------------------------------
/locales/he.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | he:
8 | table_of_contents: תוכן העניינים
9 | insert_table_of_contents: הוספת תוכן עניינים
10 | jump_bottom: דילוג לסוף
11 | toggle_toc:
12 | show_timeline: ציר זמן
13 | show_toc: תוכן
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: דרגת האמון המזערית שחייבת להיות למשתמש כדי לצפות בכפתור תוכן העניינים בחלונית הכתיבה
17 | composer_toc_text: טקסט שמופיע בחלק העליון של חלונית התצוגה המקדימה של עורך הפוסטים כדי לציין שהנושא יכלול תוכן עניינים
18 | auto_TOC_categories: להפעיל תוכן עניינים אוטומטית לנושאים בקטגוריות האלו
19 | auto_TOC_tags: להפעיל תוכן עניינים אוטומטית לנושאים עם התגיות האלו
20 | TOC_min_heading: מספר כותרות מזערי בנושא להצגת תוכן עניינים
21 | enable_TOC_for_replies: מאפשר תוכן עניינים לתגובות. תוכני עניינים לתגובות לא מושפעים מהגדרות תגיות תוכן העניינים (TOC) האוטומטיות וקטגוריות תוכן העניינים (TOC) האוטומטיות ויש להוסיף אותן ידנית.
22 |
--------------------------------------------------------------------------------
/locales/hr.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | hr:
8 |
--------------------------------------------------------------------------------
/locales/hu.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | hu:
8 |
--------------------------------------------------------------------------------
/locales/hy.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | hy:
8 |
--------------------------------------------------------------------------------
/locales/id.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | id:
8 |
--------------------------------------------------------------------------------
/locales/it.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | it:
8 | table_of_contents: sommario
9 | insert_table_of_contents: Inserisci il sommario
10 | jump_bottom: Vai alla fine
11 | toggle_toc:
12 | show_timeline: Sequenza temporale
13 | show_toc: Contenuti
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Il livello di attendibilità minimo che un utente deve avere per poter vedere il pulsante Sommario nel compositore
17 | composer_toc_text: Il testo che appare nella parte superiore del riquadro di anteprima del compositore per indicare che l'argomento avrà un sommario
18 | auto_TOC_categories: Abilita automaticamente il sommario sugli argomenti in queste categorie
19 | auto_TOC_tags: Abilita automaticamente il sommario sugli argomenti con queste etichette
20 | TOC_min_heading: Numero minimo di intestazioni in un argomento affinché il sommario venga mostrato
21 | enable_TOC_for_replies: Consente il sommario per le risposte. I sommari delle risposte non sono influenzati dalle impostazioni Etichette sommario automatiche e Categorie sommario automatico e devono essere inseriti manualmente.
22 |
--------------------------------------------------------------------------------
/locales/ja.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ja:
8 | table_of_contents: 目次
9 | insert_table_of_contents: 目次を挿入
10 | jump_bottom: 最後まで移動
11 | toggle_toc:
12 | show_timeline: タイムライン
13 | show_toc: コンテンツ
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: コンポーザーに TOC ボタンを表示するためにユーザーに必要な最低信頼レベル
17 | composer_toc_text: トピックに目次が挿入されることを示す、コンポーザーのプレビューペインの上部に表示されるテキスト
18 | auto_TOC_categories: これらのカテゴリのトピックで TOC を自動的に有効にする
19 | auto_TOC_tags: これらのタグのあるトピックで TOC を自動的に有効にする
20 | TOC_min_heading: 目次を表示するために必要なトピックの見出しの最低数
21 | enable_TOC_for_replies: 返信の TOC を許可します。返信の TOC は自動 TOC タグと自動 TOC カテゴリの設定の影響はなく、手動で挿入する必要があります。
22 |
--------------------------------------------------------------------------------
/locales/ko.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ko:
8 |
--------------------------------------------------------------------------------
/locales/lt.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | lt:
8 |
--------------------------------------------------------------------------------
/locales/lv.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | lv:
8 |
--------------------------------------------------------------------------------
/locales/nb_NO.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | nb_NO:
8 |
--------------------------------------------------------------------------------
/locales/nl.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | nl:
8 | table_of_contents: inhoudsopgave
9 | insert_table_of_contents: Inhoudsopgave invoegen
10 | jump_bottom: Naar einde
11 | toggle_toc:
12 | show_timeline: Tijdlijn
13 | show_toc: Inhoud
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Het minimale vertrouwensniveau dat een gebruiker moet hebben om de inhoudsopgaveknop te zien in de editor
17 | composer_toc_text: Tekst die bovenaan het voorbeeldvenster van de editor wordt weergegeven om aan te geven dat het topic een inhoudsopgave heeft
18 | auto_TOC_categories: Inhoudsopgave automatisch inschakelen voor topics in deze categorieën
19 | auto_TOC_tags: Inhoudsopgave automatisch inschakelen voor topics met deze tags
20 | TOC_min_heading: Minimaal aantal koppen in een topic voordat de inhoudsopgave wordt weergegeven
21 | enable_TOC_for_replies: Staat een inhoudsopgave toe voor antwoorden. Inhoudsopgaven voor antwoorden worden niet beïnvloed door de instellingen auto TOC tags en auto TOC categories en moeten handmatig worden ingevoegd.
22 |
--------------------------------------------------------------------------------
/locales/pl_PL.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | pl_PL:
8 |
--------------------------------------------------------------------------------
/locales/pt.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | pt:
8 |
--------------------------------------------------------------------------------
/locales/pt_BR.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | pt_BR:
8 | table_of_contents: tabela de conteúdo
9 | insert_table_of_contents: Inserir tabela de conteúdo
10 | jump_bottom: Ir para o fim
11 | toggle_toc:
12 | show_timeline: Linha de tempo
13 | show_toc: Conteúdo
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: O nível de confiança mínimo necessário para visualizar o botão TOC no compositor
17 | composer_toc_text: Texto exibido no topo do painel de pré-visualização do compositor para indicar que o tópico terá uma tabela de conteúdo
18 | auto_TOC_categories: Ativar automaticamente TOC em tópicos nestas categorias
19 | auto_TOC_tags: Ativar automaticamente TOC em tópicos com estas etiquetas
20 | TOC_min_heading: Quantidade mínima de cabeçalhos em um tópico para exibir a tabela de conteúdo
21 | enable_TOC_for_replies: Permitir TOC para respostas. TOCs para respostas não são afetados pelas configurações de etiquetas de TOC automáticas e categorias de TOC automáticas e devem ser inseridas manualmente.
22 |
--------------------------------------------------------------------------------
/locales/ro.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ro:
8 | table_of_contents: cuprins
9 | insert_table_of_contents: Introdu cuprins
10 | jump_bottom: Sari la final
11 | toggle_toc:
12 | show_timeline: Cronologie
13 | show_toc: Conținut
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Nivelul minim de încredere pe care trebuie să îl aibă un utilizator pentru a vedea butonul TOC în compozitor
17 | auto_TOC_categories: Activează automat TOC pentru subiectele din aceste categorii
18 | auto_TOC_tags: Activează automat TOC în subiectele cu aceste etichete
19 |
--------------------------------------------------------------------------------
/locales/ru.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ru:
8 | table_of_contents: оглавление
9 | insert_table_of_contents: Вставить оглавление
10 | jump_bottom: Перейти к концу
11 | toggle_toc:
12 | show_timeline: Шкала времени
13 | show_toc: Оглавление
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Минимальный уровень доверия, который должен иметь пользователь, чтобы увидеть кнопку оглавления в редакторе
17 | composer_toc_text: Текст, появляющийся в верхней части панели предварительного просмотра редактора и указывающий на то, что тема будет иметь оглавление
18 | auto_TOC_categories: Автоматически включает оглавление для тем в этих категориях
19 | auto_TOC_tags: Автоматически включать оглавление в темах с этими тегами
20 | TOC_min_heading: Минимальное количество заголовков в теме, чтобы отобразить оглавление
21 | enable_TOC_for_replies: Позволяет вставлять оглавление для ответов. На оглавления для ответов не влияют настройки auto TOC tags и auto TOC categories, и их необходимо вставлять вручную.
22 |
--------------------------------------------------------------------------------
/locales/sk.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sk:
8 |
--------------------------------------------------------------------------------
/locales/sl.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sl:
8 |
--------------------------------------------------------------------------------
/locales/sq.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sq:
8 |
--------------------------------------------------------------------------------
/locales/sr.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sr:
8 |
--------------------------------------------------------------------------------
/locales/sv.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sv:
8 |
--------------------------------------------------------------------------------
/locales/sw.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | sw:
8 |
--------------------------------------------------------------------------------
/locales/te.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | te:
8 |
--------------------------------------------------------------------------------
/locales/th.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | th:
8 |
--------------------------------------------------------------------------------
/locales/tr_TR.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | tr_TR:
8 | table_of_contents: içindekiler
9 | insert_table_of_contents: İçindekiler tablosu ekle
10 | jump_bottom: Sona atla
11 | toggle_toc:
12 | show_timeline: Zaman çizelgesi
13 | show_toc: İçindekiler
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: Bir kullanıcının bestecideki İçindekiler düğmesini görebilmesi için sahip olması gereken minimum güven seviyesi
17 | composer_toc_text: Bestecinin ön izleme bölmesinin en üstünde görünen ve konunun bir içerik tablosuna sahip olacağını belirten metin
18 | auto_TOC_categories: Bu kategorilerdeki konulardaki İçindekiler'i otomatik olarak etkinleştir
19 | auto_TOC_tags: Bu etiketlere sahip konulardaki İçindekiler'i otomatik olarak etkinleştir
20 | TOC_min_heading: İçindekiler tablosunun gösterilebilmesi için bir konudaki minimum başlık sayısı
21 | enable_TOC_for_replies: Yanıtlar için İçindekiler tablosuna izin verir. Yanıtlar için İçindekiler, otomatik İçindekiler etiketleri ve otomatik İçindekiler kategorileri ayarlarından etkilenmez ve manuel olarak eklenmelidir.
22 |
--------------------------------------------------------------------------------
/locales/ug.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ug:
8 |
--------------------------------------------------------------------------------
/locales/uk.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | uk:
8 |
--------------------------------------------------------------------------------
/locales/ur.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | ur:
8 |
--------------------------------------------------------------------------------
/locales/vi.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | vi:
8 |
--------------------------------------------------------------------------------
/locales/zh_CN.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | zh_CN:
8 | table_of_contents: 目录
9 | insert_table_of_contents: 插入目录
10 | jump_bottom: 跳至结尾
11 | toggle_toc:
12 | show_timeline: 时间线
13 | show_toc: 目录
14 | theme_metadata:
15 | settings:
16 | minimum_trust_level_to_create_TOC: 能够在编辑器中看到 TOC 按钮的最低信任级别
17 | composer_toc_text: 显示在编辑器预览窗格顶部的文本,用于指示该话题将有目录
18 | auto_TOC_categories: 在这些类别的话题中自动启用目录
19 | auto_TOC_tags: 在带有这些标签的话题中自动启用目录
20 | TOC_min_heading: 目录中显示的话题的最小标题数
21 | enable_TOC_for_replies: 允许使用目录进行回复。使用目录进行回复不受自动目录标签和自动目录类别设置影响,必须手动插入。
22 |
--------------------------------------------------------------------------------
/locales/zh_TW.yml:
--------------------------------------------------------------------------------
1 | # WARNING: Never edit this file.
2 | # It will be overwritten when translations are pulled from Crowdin.
3 | #
4 | # To work with us on translations, join this project:
5 | # https://translate.discourse.org/
6 |
7 | zh_TW:
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "@discourse/lint-configs": "2.21.0",
5 | "ember-template-lint": "7.7.0",
6 | "eslint": "9.27.0",
7 | "prettier": "3.5.3",
8 | "stylelint": "16.19.1"
9 | },
10 | "engines": {
11 | "node": ">= 22",
12 | "npm": "please-use-pnpm",
13 | "yarn": "please-use-pnpm",
14 | "pnpm": "9.x"
15 | },
16 | "packageManager": "pnpm@9.15.5"
17 | }
18 |
--------------------------------------------------------------------------------
/settings.yml:
--------------------------------------------------------------------------------
1 | minimum_trust_level_to_create_TOC:
2 | default: 0
3 | type: enum
4 | choices:
5 | - 1
6 | - 2
7 | - 3
8 | - 4
9 | composer_toc_text:
10 | default: "This topic will contain a table of contents"
11 | auto_TOC_categories:
12 | type: list
13 | list_type: category
14 | default: ""
15 | auto_TOC_tags:
16 | type: list
17 | list_type: tag
18 | default: ""
19 | enable_TOC_for_replies:
20 | default: false
21 | TOC_min_heading:
22 | default: 3
23 | min: 1
24 | max: 10000
25 |
--------------------------------------------------------------------------------
/spec/system/core_features_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe "Core features", type: :system do
4 | before { upload_theme_or_component }
5 |
6 | it_behaves_like "having working core features"
7 | end
8 |
--------------------------------------------------------------------------------
/spec/system/discotoc_author_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe "DiscoTOC", system: true do
4 | let!(:theme) { upload_theme_component }
5 |
6 | fab!(:category)
7 | fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
8 |
9 | fab!(:topic_1) { Fabricate(:topic) }
10 | fab!(:post_1) do
11 | Fabricate(
12 | :post,
13 | raw:
14 | "\n\n# Heading 1\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading",
15 | topic: topic_1,
16 | )
17 | end
18 |
19 | before { sign_in(user) }
20 |
21 | it "composer has table of contents button" do
22 | visit("/c/#{category.id}")
23 |
24 | find("#create-topic").click
25 | find(".toolbar-popup-menu-options").click
26 |
27 | expect(page).to have_css("[data-name='Insert table of contents']")
28 | end
29 |
30 | it "table of contents button inserts markup into composer" do
31 | visit("/c/#{category.id}")
32 |
33 | find("#create-topic").click
34 | find(".toolbar-popup-menu-options").click
35 | find("[data-name='Insert table of contents']").click
36 |
37 | expect(page).to have_css(".d-editor-preview [data-theme-toc='true']")
38 | end
39 |
40 | it "table of contents button is hidden by trust level setting" do
41 | theme.update_setting(:minimum_trust_level_to_create_TOC, "2")
42 | theme.save!
43 |
44 | visit("/c/#{category.id}")
45 |
46 | find("#create-topic").click
47 | find(".toolbar-popup-menu-options").click
48 |
49 | expect(page).to have_no_css("[data-name='Insert table of contents']")
50 | end
51 |
52 | it "table of contents button does not appear on replies" do
53 | visit("/t/#{topic_1.id}")
54 |
55 | find(".reply").click
56 | find(".toolbar-popup-menu-options").click
57 |
58 | expect(page).to have_no_css("[data-name='Insert table of contents']")
59 | end
60 |
61 | context "when enable TOC for replies" do
62 | before do
63 | theme.update_setting(:enable_TOC_for_replies, true)
64 | theme.save!
65 | end
66 |
67 | it "table of contents button does appear on replies" do
68 | visit("/t/#{topic_1.id}")
69 |
70 | find(".reply").click
71 | find(".toolbar-popup-menu-options").click
72 |
73 | expect(page).to have_css("[data-name='Insert table of contents']")
74 | end
75 | end
76 | end
77 |
--------------------------------------------------------------------------------
/spec/system/discotoc_progress_user_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe "DiscoTOC", system: true do
4 | let!(:theme) { upload_theme_component }
5 |
6 | fab!(:category)
7 | fab!(:tag)
8 |
9 | fab!(:topic_1) { Fabricate(:topic, category: category, tags: [tag]) }
10 | fab!(:topic_2) { Fabricate(:topic, category: category, tags: [tag]) }
11 |
12 | fab!(:post_1) do
13 | Fabricate(
14 | :post,
15 | raw:
16 | "\n\n# Heading 1\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading",
17 | topic: topic_1,
18 | )
19 | end
20 |
21 | fab!(:post_2) do
22 | Fabricate(
23 | :post,
24 | raw:
25 | "\n# Heading 1\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading",
26 | topic: topic_2,
27 | )
28 | end
29 |
30 | fab!(:post_3) do
31 | Fabricate(
32 | :post,
33 | raw:
34 | "intentionally \n long \n content \n so \n there's \n plenty \n to be \n scrolled \n past \n which \n will \n force \n the \n timeline \n to \n hide \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll ",
35 | topic: topic_1,
36 | )
37 | end
38 |
39 | fab!(:post_4) do
40 | Fabricate(
41 | :post,
42 | raw:
43 | "\n\n# Heading For Reply 1\nContent for the first heading\n## Heading For Reply 2\nContent for the second heading\n### Heading For Reply 3\nContent for the third heading\n# Heading For Reply 4\nContent for the fourth heading",
44 | topic: topic_1,
45 | )
46 | end
47 |
48 | fab!(:post_5) do
49 | Fabricate(
50 | :post,
51 | raw:
52 | "intentionally \n long \n content \n so \n there's \n plenty \n to be \n scrolled \n past \n which \n will \n force \n the \n timeline \n to \n hide \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll ",
53 | topic: topic_1,
54 | )
55 | end
56 |
57 | it "table of contents button appears in mobile view" do
58 | visit("/t/#{topic_1.id}/?mobile_view=1")
59 |
60 | expect(page).to have_css(".d-toc-mini")
61 | end
62 |
63 | it "clicking the toggle button toggles the timeline" do
64 | visit("/t/#{topic_1.id}/?mobile_view=1")
65 |
66 | find(".d-toc-mini").click
67 |
68 | expect(page).to have_css(".d-toc-wrapper.overlay")
69 | end
70 |
71 | it "timeline toggle does not appear when the progress bar timeline is expanded" do
72 | visit("/t/#{topic_1.id}/?mobile_view=1")
73 |
74 | find("#topic-progress").click
75 |
76 | expect(page).to have_no_css(".timeline-fullscreen .timeline-toggle")
77 | end
78 |
79 | it "d-toc-mini is hidden when scrolled past the first post" do
80 | visit("/t/#{topic_1.id}/?mobile_view=1")
81 |
82 | page.execute_script <<~JS
83 | window.scrollTo(0, document.body.scrollHeight);
84 | JS
85 |
86 | expect(page).to have_no_css(".d-toc-mini")
87 | end
88 |
89 | it "d-toc-mini does not appear if the first post does not contain the markup" do
90 | visit("/t/#{topic_2.id}/?mobile_view=1")
91 |
92 | expect(page).to have_no_css(".d-toc-mini")
93 | end
94 |
95 | it "d-toc-mini will appear without markup if auto_TOC_categories is set to the topic's category" do
96 | theme.update_setting(:auto_TOC_categories, "#{category.id}")
97 | theme.save!
98 |
99 | visit("/t/#{topic_2.id}/?mobile_view=1")
100 |
101 | expect(page).to have_css(".d-toc-mini")
102 | end
103 |
104 | context "when disable TOC for replies" do
105 | before do
106 | theme.update_setting(:enable_TOC_for_replies, false)
107 | theme.save!
108 | end
109 |
110 | it "table of contents button won't appears in mobile view for replies" do
111 | visit("/t/-/#{topic_1.id}/3/?mobile_view=1")
112 |
113 | expect(page).to have_no_css(".d-toc-mini")
114 | end
115 | end
116 |
117 | context "when enable TOC for replies" do
118 | before do
119 | theme.update_setting(:enable_TOC_for_replies, true)
120 | theme.save!
121 | end
122 |
123 | it "table of contents button appears in mobile view for replies" do
124 | visit("/t/-/#{topic_1.id}/3/?mobile_view=1")
125 |
126 | expect(page).to have_css(".d-toc-mini")
127 | end
128 |
129 | it "d-toc-mini will not appear without markup for replies regardless of auto_TOC_categories and auto_TOC_tags" do
130 | theme.update_setting(:auto_TOC_categories, "#{category.id}")
131 | theme.update_setting(:auto_TOC_tags, "#{tag.name}")
132 | theme.save!
133 |
134 | visit("/t/-/#{topic_1.id}/2/?mobile_view=1")
135 |
136 | expect(page).to have_no_css(".d-toc-mini")
137 | end
138 | end
139 |
140 | it "d-toc-mini will not appear automatically if auto_TOC_categories is set to a different category" do
141 | theme.update_setting(:auto_TOC_categories, "99")
142 | theme.save!
143 |
144 | visit("/t/#{topic_2.id}/?mobile_view=1")
145 |
146 | expect(page).to have_no_css(".d-toc-mini")
147 | end
148 |
149 | it "d-toc-mini will appear without markup if auto_TOC_tags is set to the topic's tag" do
150 | theme.update_setting(:auto_TOC_tags, "#{tag.name}")
151 | theme.save!
152 |
153 | visit("/t/#{topic_2.id}/?mobile_view=1")
154 |
155 | expect(page).to have_css(".d-toc-mini")
156 | end
157 |
158 | it "d-toc-mini will not appear automatically if auto_TOC_tags is set to a different tag" do
159 | theme.update_setting(:auto_TOC_tags, "wrong-tag")
160 | theme.save!
161 |
162 | visit("/t/#{topic_2.id}/?mobile_view=1")
163 |
164 | expect(page).to have_no_css(".d-toc-mini")
165 | end
166 |
167 | it "d-toc-mini does not appear if it has fewer headings than TOC_min_heading setting" do
168 | theme.update_setting(:TOC_min_heading, 5)
169 | theme.save!
170 |
171 | visit("/t/#{topic_1.id}/?mobile_view=1")
172 |
173 | expect(page).to have_no_css(".d-toc-mini")
174 | end
175 | end
176 |
--------------------------------------------------------------------------------
/spec/system/discotoc_timeline_user_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe "DiscoTOC", system: true do
4 | let!(:theme) { upload_theme_component }
5 |
6 | fab!(:category)
7 | fab!(:tag)
8 |
9 | fab!(:topic_1) { Fabricate(:topic, category: category, tags: [tag]) }
10 | fab!(:topic_2) { Fabricate(:topic, category: category, tags: [tag]) }
11 |
12 | fab!(:post_1) do
13 | Fabricate(
14 | :post,
15 | raw:
16 | "\n\n# Heading 1\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading",
17 | topic: topic_1,
18 | )
19 | end
20 |
21 | fab!(:post_2) do
22 | Fabricate(
23 | :post,
24 | raw:
25 | "\n# Heading 1\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading",
26 | topic: topic_2,
27 | )
28 | end
29 |
30 | fab!(:post_3) do
31 | Fabricate(
32 | :post,
33 | raw:
34 | "intentionally \n long \n content \n so \n there's \n plenty \n to be \n scrolled \n past \n which \n will \n force \n the \n timeline \n to \n hide \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll ",
35 | topic: topic_1,
36 | )
37 | end
38 |
39 | fab!(:post_4) do
40 | Fabricate(
41 | :post,
42 | raw:
43 | "\n\n# Heading For Reply 1\nContent for the first heading\n## Heading For Reply 2\nContent for the second heading\n### Heading For Reply 3\nContent for the third heading\n# Heading For Reply 4\nContent for the fourth heading",
44 | topic: topic_1,
45 | )
46 | end
47 |
48 | fab!(:post_5) do
49 | Fabricate(
50 | :post,
51 | raw:
52 | "intentionally \n long \n content \n so \n there's \n plenty \n to be \n scrolled \n past \n which \n will \n force \n the \n timeline \n to \n hide \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll \n scroll ",
53 | topic: topic_1,
54 | )
55 | end
56 |
57 | it "table of contents appears when the relevant markup is added to first post in topic" do
58 | visit("/t/#{topic_1.id}")
59 |
60 | expect(page).to have_css(".d-toc-item.d-toc-h1")
61 | end
62 |
63 | it "clicking the toggle button toggles the timeline" do
64 | visit("/t/#{topic_1.id}")
65 |
66 | find(".timeline-toggle").click
67 |
68 | expect(page).to have_css(".timeline-scrollarea-wrapper")
69 |
70 | find(".timeline-toggle").click
71 |
72 | expect(page).to have_css(".d-toc-item.d-toc-h1")
73 | end
74 |
75 | it "timeline does not appear when the table of contents is shown" do
76 | visit("/t/#{topic_1.id}")
77 |
78 | expect(page).to have_no_css(".topic-timeline")
79 | end
80 |
81 | it "table of contents is hidden when scrolled past the first post" do
82 | visit("/t/#{topic_1.id}")
83 |
84 | page.execute_script <<~JS
85 | window.scrollTo(0, document.body.scrollHeight);
86 | JS
87 |
88 | expect(page).to have_css(".topic-timeline")
89 | end
90 |
91 | it "table of contents does not appear if the first post does not contain the markup" do
92 | visit("/t/#{topic_2.id}")
93 |
94 | expect(page).to have_no_css(".d-toc-item.d-toc-h1")
95 | end
96 |
97 | it "table of contents updates the highlighted section after navigating directly to other topic" do
98 | source_topic = Fabricate(:topic, category: category, tags: [tag])
99 |
100 | Fabricate(
101 | :post,
102 | topic: source_topic,
103 | raw:
104 | "\n\n# Heading 1 on the source topic\nContent for the first heading\n## Heading 2\nContent for the second heading\n### Heading 3\nContent for the third heading\n# Heading 4\nContent for the fourth heading\nOther topic",
105 | )
106 | visit("/t/#{source_topic.id}")
107 |
108 | expect(page).to have_css(
109 | ".d-toc-item.d-toc-h1.active a[data-d-toc='toc-h1-heading-1-on-the-source-topic']",
110 | )
111 |
112 | find("a[href='/t/#{topic_1.slug}/#{topic_1.id}']").click
113 |
114 | expect(page).to have_css(".d-toc-item.d-toc-h1.active a[data-d-toc='toc-h1-heading-1']")
115 | expect(page).to have_no_css("a[data-d-toc='toc-h1-heading-1-on-the-source-topic']")
116 | end
117 |
118 | it "timeline will appear without markup if auto_TOC_categories is set to the topic's category" do
119 | theme.update_setting(:auto_TOC_categories, "#{category.id}")
120 | theme.save!
121 |
122 | visit("/t/#{topic_2.id}")
123 |
124 | expect(page).to have_css(".d-toc-item.d-toc-h1")
125 | end
126 |
127 | it "timeline will not appear automatically if auto_TOC_categories is set to a different category" do
128 | theme.update_setting(:auto_TOC_categories, "99")
129 | theme.save!
130 |
131 | visit("/t/#{topic_2.id}")
132 |
133 | expect(page).to have_no_css(".d-toc-item.d-toc-h1")
134 | end
135 |
136 | it "timeline will appear without markup if auto_TOC_tags is set to the topic's tag" do
137 | theme.update_setting(:auto_TOC_tags, "#{tag.name}")
138 | theme.save!
139 |
140 | visit("/t/#{topic_2.id}")
141 |
142 | expect(page).to have_css(".d-toc-item.d-toc-h1")
143 | end
144 |
145 | it "timeline will not appear automatically if auto_TOC_tags is set to a different tag" do
146 | theme.update_setting(:auto_TOC_tags, "wrong-tag")
147 | theme.save!
148 |
149 | visit("/t/#{topic_2.id}")
150 |
151 | expect(page).to have_no_css(".d-toc-item.d-toc-h1")
152 | end
153 |
154 | it "timeline does not appear if it has fewer headings than TOC_min_heading setting" do
155 | theme.update_setting(:TOC_min_heading, 5)
156 | theme.save!
157 |
158 | visit("/t/#{topic_1.id}")
159 |
160 | expect(page).to have_no_css(".d-toc-item.d-toc-h1")
161 | end
162 |
163 | context "when enable TOC for replies" do
164 | before do
165 | theme.update_setting(:enable_TOC_for_replies, true)
166 | theme.save!
167 | end
168 |
169 | it "timeline does not appear for replies when the table of contents is shown" do
170 | visit("/t/-/#{topic_1.id}/3")
171 |
172 | expect(page).to have_no_css(".topic-timeline")
173 | end
174 |
175 | it "d-toc-mini will not appear without markup for replies regardless of auto_TOC_categories and auto_TOC_tags" do
176 | theme.update_setting(:auto_TOC_categories, "#{category.id}")
177 | theme.update_setting(:auto_TOC_tags, "#{tag.name}")
178 | theme.save!
179 |
180 | visit("/t/-/#{topic_1.id}/2")
181 |
182 | expect(page).to have_no_css(".d-toc-item.d-toc-h1")
183 | end
184 | end
185 | end
186 |
--------------------------------------------------------------------------------
/stylelint.config.mjs:
--------------------------------------------------------------------------------
1 | export default {
2 | extends: ["@discourse/lint-configs/stylelint"],
3 | };
4 |
--------------------------------------------------------------------------------
/translator.yml:
--------------------------------------------------------------------------------
1 | # Configuration file for discourse-translator-bot
2 |
3 | files:
4 | - source_path: locales/en.yml
5 | destination_path: translations.yml
6 |
--------------------------------------------------------------------------------