DiscoTOC - automatisches Inhaltsverzeichnis

:discourse2: Summary DiscoTOC will allow you to generate an interactive table of contents for your topics with one click!
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/DiscoTOC
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Samples

Desktop

Mobile

Features

toc = table of contents

  • Automatically generates the entire toc via a button in the composer gear menu

  • The toc will always be on the screen - scrolls with content like the topic progress widget

  • As you scroll past sections in the topic, the active element in the table of contents will be set to active (blue highlight)

  • adds id attributes to headings (you can link to a specific section from another topic / post)

  • clicking on any link in the toc will instruct the browser to navigate to relevant section (smooth-scrolling)

  • adds a copy-able link next to each heading (if you want to link to it)

  • RTL support

  • The colors are based on your current active color palette

How does it work?

In a nutshell, it looks for headings in topics which are marked to have a toc (via the composer button) and if it turns out the current topic is marked, then it takes all the headings and puts them in the toc (nested in order of heading levels) - this means that your markdown must be syntactically correct.

# heading 1
## heading 2
### heading 3
#### heading 4
##### heading 5
###### heading 6

You’re free to go back and fourth in heading levels, but the order must be correct

# heading 2 
## heading 3
## heading 3
### heading 4
## heading 3
# heading 2

etc...

In order for the links in the toc to work, headings must have id attributes. The component will check if the headings already have ids and if they do, then they are respected. This is handy if you ever manually created a toc.

If the headings don’t have ids, then it will generate an id for each heading based on its text (unwanted characters are stripped out)

once all of that is done, it will also add a link next to each button that links directly to that section:

Settings

Name Description
minimum trust level to create TOC The minimum trust level a user must have in order to see the TOC button in the composer
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
auto TOC categories Automatically enable TOC on topics in these categories
auto TOC tags Automatically enable TOC on topics with these tags
TOC min heading Minimum number of headings in a topic for the table of contents to be shown

Translations

Translation Default
table_of_contents table of contents
insert_table_of_contents Insert table of contents
jump_bottom Jump to end
toggle_toc.show_timeline Timeline
toggle_toc.show_toc Contents

The theme comes with three strings that you can translate or change.

table_of_contents: "table of contents"

this used for the button that opens the toc on mobile

insert_table_of_contents: "Insert table of contents"

this is used as the text for the toc button in the composer gear menu

topic_will_contain_a_table_of_contents: "This topic will contain a table of contents"

This is the text that shows up in the composer preview to indicate that the a toc will be generated for the topic

How do I create a toc?

  1. Write a topic with syntactically correct headings
  2. Click the toc button in the gear menu (only shows up when creating a regular topic - replies and PMs are ignored
  3. Profit.

What happens to the topic progress widget when a topic has a toc?

As you can probably guess, there’s no space to show both at the same time, so the way this component works is as follows

in a topic with a toc, the topic progress widget is hidden while the first post is on screen, and you see the toc instead.

Once you scroll past the first post, the toc will not scroll with you and the topic progress will be shown instead while you read any replies.

So, first posts get the toc, and subsequent posts get the regular topic progress widget.

The happens on both desktop and mobile.

Are there any downsides to using this component?

Nothing I am aware of, all the changes are done on the client-side. So you can easily remove the component and your posts would go back to the way they were before you installed it.

Limitations

This component assumes the standard topic layout. As such, it won’t work with themes that modify that layout such as the Vincent theme. Support for popular themes that modify the layout will come at a later stage in the form of component settings.

Credit

I started with Greg Franko’s tocify.js library. However, it looks like it’s not been updated in a while, so this is essentially a hard-fork that removes a lot of unnecessary features, integrates and styles the rest for Discourse.

So, there are no external requests and the total size is ~ 4kb gzip.

Big thanks to @erlend_sh for lots of valuable feedback and to @david for his help with translations.

:discourse2: Hosted by us? Theme components are available to use on our Pro, Business and Enterprise plans.

Last edited by @tobiaseigen 2025-06-24T03:17:08Z

Check documentPerform check on document:
181 „Gefällt mir“

4 Beiträge wurden in ein neues Thema aufgeteilt: Wie verschiebt man das Inhaltsverzeichnis auf die linke Seite des Beitrags?

Ich weiß nicht, wie diese Komponente implementiert ist oder viel über die Frontend-Struktur von Discourse, daher kann ich nur eine Vermutung anstellen.

Könnte der Fortschrittsbalken nur angezeigt werden a) wenn mehr als 1 Beitrag im Thema vorhanden ist und b) sein Start vom 2. Beitrag an (anstelle des 3.) angepasst werden, aber auch c) einen angemessenen oberen/unteren Abstand zu einem der beiden Elemente hinzugefügt werden, um sicherzustellen, dass der andere genügend Abstand hat (z. B. 1vh), damit es nicht seltsam aussieht?

Mit anderen Worten, anstatt den gesamten 2. Beitrag als Abstand zu verwenden, CSS verwenden, um etwas Platz dazwischen zu ermöglichen (falls mehr als 1 Beitrag vorhanden ist).

Nochmals, das ergibt möglicherweise überhaupt keinen Sinn, da ich nicht viel darüber weiß, wie das im Moment funktioniert.

3 „Gefällt mir“

Hallo! Wir haben kürzlich DiscoTOC für unsere Foren installiert und wollten wissen, ob es möglich ist, die Komponente dazu zu bringen, Alternativtexte in Bildern zu lesen? Wir haben Bilder für einige Patch-Hinweis-Überschriften verwendet…

so wie hier:
Performance and Stability

Und leider scheint das TOC-System ein Bild nicht als Überschrift analysieren zu können, wodurch ein leerer Eintrag in der Liste erstellt wird und ein Link, der zu einer leeren Seite führt. Gibt es dafür eine Umgehungsmöglichkeit, abgesehen davon, „keine Bilder zu verwenden“? Vielen Dank! Ansonsten lieben wir das System.

1 „Gefällt mir“

Ich vermute, die Lösung besteht darin, keine Bilder als Überschriften zu verwenden, aber möglicherweise gibt es eine Möglichkeit, dies durch das Hinzufügen von Code zu Ihrer Website zu erreichen, der sich in den DiscoTOC-Code einklinkt. Ob es sich lohnt, dies zu untersuchen, hängt davon ab, wie wichtig es Ihnen ist, Bilder in den Überschriften des Beitrags zu verwenden.

3 „Gefällt mir“

Wir verwenden seit geraumer Zeit konsistent Bilder als Überschriften in unseren Patch Notes, und dies ist Teil unseres Brandings und unserer Präsentation – nicht nur in den Foren, sondern auch auf Steam und ähnlichen Plattformen. Wir möchten die Möglichkeit haben, weiterhin Bilder als Überschriften zu verwenden, während wir DiscoTOC nutzen, um die Konsistenz zu wahren.

DiscoTOC war für andere Dinge großartig, wie zum Beispiel für eine AMA-Zusammenfassung, einen Megapost über unsere dedizierte Server-Launcher-Anwendung, Anleitungen für neue Spieler usw. Wir mögen das System sehr, würden uns aber über ein wenig zusätzliche Funktionalität für die Art und Weise, wie wir Patch Notes präsentieren, freuen.

1 „Gefällt mir“

Die Ankerfunktionalität der Überschriften in dieser Komponente kollidiert leicht mit der Funktionalität „Automatische Header-Linkshinzugefügt in 2.7.0beta6, da Überschriften beim Darüberfahren zwei Symbole erhalten, eines von Discourse und eines von DiscoTOC. Gibt es eine Möglichkeit, dies zu umgehen?

1 „Gefällt mir“

Hallo,

Sie können den Anker für Automatische Kopfzeilen-Links mit

.anchor {
  display: none;
}

ausblenden.

Hallo dodesz,

Ich habe die Beitragsbreite viel größer als die Standardbreite gemacht, und nach der Installation dieser Komponente sieht es etwas falsch aus. Könntest du mir sagen, wie ich dieses Problem beheben kann?

:heart: Danke!

Selection_839

1 „Gefällt mir“

Auf einem Forum, das Discourse 2.8.0.beta4 (90232af778) verwendet, führt die Einbindung der DiscoTOC-Komponente zu einer Fehlermeldung:

oops

Die Komponente war zuvor aktiviert und verursachte auch bei der zuvor installierten Discourse-Version ein Problem, obwohl ich nicht sagen kann, welche Version das war.

Können Sie irgendwelche Fehlermeldungen im Zusammenhang mit dem Problem in den Fehlerprotokollen Ihrer Website finden?

Diese Fehlermeldung ist ein Backend-Fehler, während DiscoTOC eine Front-End-Theme-Komponente ist, daher ist es unwahrscheinlich, dass sie zusammenhängen. Haben Sie Plugins installiert?

1 „Gefällt mir“

Leider konnte ich im /logs nichts Nützliches finden.

Ja, hier ist der relevante Auszug aus app.yml:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-openid-connect.git
          - git clone https://github.com/discourse/discourse-checklist.git
          - git clone https://github.com/discourse/discourse-push-notifications.git
          - git clone https://github.com/discourse/discourse-characters-required.git
          - git clone https://github.com/angusmcleod/discourse-news.git
          - git clone https://github.com/discourse/discourse-data-explorer.git
          - git clone https://github.com/DNOeV/discourse-watch-category.git
          - git clone https://github.com/discourse/discourse-footnote.git
          - git clone https://github.com/discourse/discourse-knowledge-explorer.git
1 „Gefällt mir“

Wenn sich eine Überschrift innerhalb eines Zitats befindet, wird die Überschrift nicht im Inhaltsverzeichnis (TOC) angezeigt. Könnte dieses Verhalten geändert werden?

Diese Überschrift wird nicht im TOC angezeigt

Zitierter Inhalt

Diese Überschrift wird im TOC angezeigt

Zitierter Inhalt

Ich weiß nicht, wie es funktionieren soll, aber normalerweise nicht, da es Teil des Zitats und keine Überschrift für diesen Text ist.

1 „Gefällt mir“

Könnten Sie stattdessen versuchen, das HTML <blockquote> zu verwenden? Das würde es ermöglichen, dass die Überschrift # am Anfang einer Zeile steht.

Bsp.:

<blockquote>

### Anker-Überschrift

</blockquote>

Anker-Überschrift

Ich habe es noch nicht in einem TOC (Inhaltsverzeichnis) ausprobiert, aber es scheint mit den automatisch generierten Anker-Überschriften in einem normalen Beitrag zu funktionieren.

Warum möchten Sie, dass Überschriften in Anführungszeichen im Inhaltsverzeichnis (TOC) angezeigt werden? Was ist Ihr Anwendungsfall?

Vielen Dank für die Idee. Es hat bei mir allerdings nicht funktioniert.

Hier ist ein Beispiel dafür, wann ich Zitate verwende, um Inhalte visuell zu strukturieren, die unter dem Themenbereich: Alter beginnen

3 „Gefällt mir“

Warum verwenden Sie diese Art von Zitaten? Die Angabe der Quelle reicht aus. Außerdem ist das grammatikalisch falsch, auch im Englischen.

Ist das ein Fehler oder nur ein anderer Benutzer, aber… wie soll ich das TOC (Inhaltsverzeichnis) schließen? Ich habe nach grundlegenden Anweisungen gesucht, wie ein Endbenutzer private Nachrichten verwenden sollte, und bin natürlich zur Dokumentation für neue Benutzer gegangen und habe das TOC geöffnet, um zu sehen, ob es dort Informationen gibt.

Ich habe ein iPad und DiscourseHub verwendet.

Ich erhielt dies:

kuva

Das TOC ist in Ordnung. Aber es überlappt Text und ich konnte es nicht wieder ausblenden. Was habe ich also falsch gemacht, oder gar nichts :pleading_face: