DiscoTOC - sommario automatico

: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.

181 Mi Piace
Automatic Table of Contents generation
Creative Uses of Discourse
Wiki improvement – Split content into multiple sections?
Blog Post Styling
Linking to a heading within a post or topic
Understanding Discourse for new users
:cn: DiscoTOC 自动内容表格
How do you create a table of content like this one?
What are the different ways to customize content inside a post (custom attributes and such)
How to get topic navigation menu
Theme Components - Can Discourse hosted sites install them?
Big Header - Little Header
How can i show a floating sticky 300x250 Adsense Ad on right side bar of topic page above the fold?
Tagged topic progress bar - feasible or not?
Timeline with labelled step by step sections - how is this achieved?
Reader Mode
Is anyone working on a Discourse Wiki?
How To Add Marker To Table Of Contents Feature?
Traditional multi level hierarchy vs flat discourse hierarchy
How do I add a table of contents sidebar to a topic?
Cannot deep link to anchor in text
How can I compare arbitrary revisions of a post?
Understanding Discourse for new users
Problem with DiscoTOC: TypeError: _offsetCalculator.headerOffset is not a function
How to create an In-app Knowledge Base with Discourse Docs?
OP Contents on Progress Bar
How to get topic sidebar
Customizing your site with existing theme components
Link to headers (anchor links)
Outline Enable
What is essential content for a new community?
Tools for creating image-heavy articles
Adding DiscoTOC to Published Pages
Customize Your Site Branding
Discourse Doc Categories
Gif icon not displaying and showing error
Must have plugins and components for Discourse?
I created a bookmarklet to create the table of content for forum posts
Could a List of Recommended Topics Be Added to the Top Menu?
?page=n URLs have high CLS hence bad SEO
Something recently changed, can't increase `--topic-body-width`
How to enable side navigation?
Improve iPad screen real estate
Missing strings (DiscoTOC)
Missing anchor links in certain TOC topics?
DiscoTOC not showing in composer after latest component update
Missing anchor links in certain TOC topics?
How to create a documentation theme used by discourse
Where's Jump to end?
Handling anchors in posts created with markdown
Reader Mode
Hidden Timeline button
Horizon Theme
Linking to a heading within a post or topic
Bulk Export of Raw Post Sources with Markup
:cn: Discourse Post Formatting Guide 加点格式,让帖子多姿多彩
Wiki table of contents on pro plan
Auto-Linkify Words
Collections
Living with corrupted SVGs for almost a year. Need Help!
Require users to "Reply as Linked Topic"
Links not working
Blog Post Styling
Using Posts as a Wiki?
Using Posts as a Wiki?
Is anyone working on a Discourse Wiki?
Using Posts as a Wiki?
Using Posts as a Wiki?
DiscoTOC & Brand Header - using together
Docs: Add link to top menu
Layouts Plugin
More than two levels of [details]
Discourse Docs
Category page with fixed organization of topics
Blog Post Styling
Inlink the topics within the same article
Navigating to local URL fragment doesn't modify browser history
Relating to Profile Picture Scroll Functionality
Copy pasting nested lists from Word into a post
Need to include PGN (chess game notation) in a post
How can I get a table of contents for my docs?
Linking to a heading within a post
Topic list on the right side
Set up Slack notifications using the discourse-chat-integration plugin
Wrong title in the history popup (firefox)
Possible to insert post in a topic
I created a bookmarklet to create the table of content for forum posts
How to add table of content sidebar beside a topic?

4 post sono stati divisi in un nuovo argomento: Come spostare il TOC sul lato sinistro del post?

Non so come sia implementato questo componente o molto sulla struttura frontend di Discourse, quindi posso solo fare un’ipotesi.

La barra di avanzamento potrebbe essere mostrata solo a) se ci sono più di 1 post nell’argomento e b) la sua partenza potrebbe essere regolata dal 2° post (invece che dal 3°), ma anche c) aggiungere un margine inferiore/superiore confortevole a uno dei due elementi per assicurarsi che l’altro rimanga sufficientemente distante (es. 1vh) da non sembrare strano?

In altre parole, invece di usare l’intero 2° post come spazio, usa il CSS per consentire un po’ di spazio tra loro (se c’è più di 1 post).

Ancora una volta, questo potrebbe non avere alcun senso dato che non so molto sul modo in cui funziona al momento.

3 Mi Piace

Ciao! Abbiamo recentemente installato DiscoTOC per i nostri forum e ci chiedevamo se fosse possibile far leggere al componente il testo alternativo (alt text) nelle immagini? Abbiamo usato immagini per alcune intestazioni delle note di rilascio…

come questa:
Performance and Stability

E sfortunatamente il sistema TOC non sembra in grado di analizzare un’immagine come intestazione, creando una voce vuota nell’elenco e creando un link che porta a una pagina vuota. C’è qualche soluzione alternativa a questo oltre a “non usare immagini”? Grazie! Per il resto, adoriamo il sistema.

1 Mi Piace

La mia ipotesi è che la soluzione sia non usare immagini come titoli, ma forse ci sarà un modo per farlo funzionare aggiungendo del codice al tuo sito che si agganci al codice di DiscoTOC. Se valga la pena esaminare questa possibilità dipenderà da quanto sia importante per te usare immagini nei titoli dei post.

3 Mi Piace

Abbiamo utilizzato immagini come intestazioni nelle nostre note sulla patch in modo coerente per un bel po’ di tempo ormai, ed è parte del nostro marchio e della nostra presentazione; non solo sui forum, ma anche su Steam e simili. Vorremmo avere la possibilità di continuare a utilizzare immagini come intestazioni pur utilizzando DiscoTOC per mantenere la coerenza.

DiscoTOC è stato ottimo per altre cose, come un riepilogo di AMA, un megapost sulla nostra applicazione di avvio del server dedicato, guide per i nuovi giocatori, ecc. Ci piace molto il sistema, ma vorremmo un po’ di funzionalità aggiuntive per il modo in cui presentiamo le note sulla patch.

1 Mi Piace

La funzionalità di ancoraggio dell’intestazione su questo componente è leggermente in conflitto con la funzionalità Automatic header links aggiunta in 2.7.0beta6, poiché le intestazioni ottengono due icone al passaggio del mouse, una da Discourse e una da DiscoTOC. C’è un modo per aggirare questo problema?

1 Mi Piace

Ciao,

Puoi nascondere l’ancora Automatic header links con

.anchor {
  display: none;
}

Ciao dodesz,

Ho reso la larghezza del post molto più grande di quella predefinita e dopo aver installato questo componente sembra sbagliata, potresti dirmi come risolvere questo problema?

:heart: grazie!

Selection_839

1 Mi Piace

Su un forum che esegue Discourse 2.8.0.beta4 (90232af778), l’inclusione del componente DiscoTOC porta a un messaggio di errore:

oops

Il componente era stato attivato in precedenza e aveva sollevato un problema anche con la versione di Discourse precedentemente installata, anche se non so quale fosse quella versione.

Riesci a trovare messaggi di errore relativi al problema nei log degli errori del tuo sito?

Quel message d’erreur est une erreur de backend, tandis que DiscoTOC est un thème-composant de frontend, il est donc difficile qu’ils soient liés. Avez-vous installé des plugins ?

1 Mi Piace

Sfortunatamente, non sono riuscito a trovare nulla di utile in /logs.

Sì, ecco l’estratto pertinente da 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 Mi Piace

Quando un’intestazione è all’interno di una citazione, l’intestazione non viene visualizzata nel TOC. Si potrebbe cambiare questo comportamento?

Questa intestazione non apparirà nel TOC

Contenuto citato

Questa intestazione APPARE nel TOC

Contenuto citato

Non so come sia previsto che funzioni, ma normalmente no perché fa parte di una citazione, non di un titolo di quel testo.

1 Mi Piace

Potresti provare a usare l’HTML <blockquote> invece? Ciò consentirebbe all’intestazione # di trovarsi all’inizio di una riga.

Esempio:

<blockquote>

### Intestazione di ancoraggio

</blockquote>

Intestazione di ancoraggio

Non l’ho provato in un TOC (indice), ma sembra funzionare con le intestazioni con ancoraggio automatico in un post normale.

Perché vuoi che le intestazioni tra virgolette appaiano nell’indice? Qual è il tuo caso d’uso?

Grazie per l’idea. Tuttavia, non ha funzionato per me.

Ecco un esempio di quando uso le citazioni per strutturare visivamente il contenuto che inizia sotto Area Problematica: Età

3 Mi Piace

Perché stai usando le citazioni in quel modo? Indicare la fonte è sufficiente. Inoltre, grammaticalmente è sbagliato, anche in inglese.

È un bug o solo un altro utente, ma… come dovrei chiudere il TOC? Stavo cercando istruzioni di base su come un utente finale dovrebbe usare i messaggi privati e ovviamente sono andato alla documentazione per i nuovi utenti e ho aperto il TOC per vedere se c’erano informazioni.

Stavo usando iPad e DiscourseHub.

Ho ottenuto questo:

kuva

Il TOC va bene. Ma si sovrappone al testo e non sono riuscito a farlo nascondere di nuovo. Quindi cosa diavolo ho sbagliato, o non ho fatto affatto :pleading_face: