DiscoTOC - 自動目次

: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

4件の投稿が新しいトピックに分割されました:目次を投稿の左側に移動するには?

このコンポーネントがどのように実装されているか、またDiscourseのフロントエンド構造についてあまり知らないため、推測しかできません。

プログレスバーを a) トピック内の投稿が2つ以上ある場合のみ表示し、b) 開始位置を3番目ではなく2番目の投稿からに調整し、さらに c) 2つの要素のどちらかに快適な上下マージンを追加して、もう一方から十分に離れている(例:1vh)ようにして、見た目が奇妙にならないようにすることはできないでしょうか?

つまり、2番目の投稿全体を間隔として使用する代わりに、CSSを使用して(投稿が2つ以上ある場合に限り)それらの間にいくらかのスペースを設けるということです。

繰り返しますが、現在の動作についてあまり知らないため、これは全く意味をなさないかもしれません。

「いいね!」 3

こんにちは!フォーラムにDiscoTOCを最近インストールしたのですが、このコンポーネントで画像の代替テキストを読み取ることが可能かどうか疑問に思っています。パッチノートのヘッダーに画像を使用しました…

次のように:
Performance and Stability

残念ながら、TOCシステムは画像をヘッダーとして解析できないようで、リストに空白のエントリを作成し、空白のページに移動するリンクを作成します。 「画像を使用しない」以外の回避策はありますか?ありがとうございます!それ以外ではこのシステムを気に入っています。

「いいね!」 1

私の推測では、見出しとして画像を使用しないのが解決策ですが、DiscoTOC コードにフックするコードをサイトに追加することで、動作させられる可能性があります。投稿の見出しに画像を使用することがどれだけ重要かによって、それを調査する価値があるかどうかが決まるでしょう。

「いいね!」 3

長らくパッチノートで一貫して画像を見出しとして使用しており、これはフォーラムだけでなくSteamなどでも、私たちのブランディングとプレゼンテーションの一部となっています。一貫性を保つため、DiscoTOCを使用しながらも、引き続き画像を見出しとして使用できる機能を希望しています。

DiscoTOCは、AMA(Ask Me Anything)の要約、専用サーバーランチャーアプリに関するメガポスト、新規プレイヤーガイドなど、他の用途で非常に役立っています。私たちはこのシステムを非常に気に入っていますが、パッチノートの提示方法に関して、もう少し機能が追加されることを望んでいます。

「いいね!」 1

このコンポーネントの見出しアンカー機能は、2.7.0beta6 で追加された自動ヘッダーリンク」機能とわずかに競合します。これは、見出しにマウスオーバーすると、Discourse から 1 つ、DiscoTOC から 1 つの合計 2 つのアイコンが表示されるためです。これを回避する方法はありますか?

「いいね!」 1

こんにちは。

自動ヘッダーリンクのアンカーは、以下を使用して非表示にできます。

.anchor {
  display: none;
}

dodeszさん、こんにちは。

デフォルトよりも投稿の幅をかなり広く設定したのですが、このコンポーネントをインストールした後、見た目が何かおかしくなってしまいました。この問題を修正する方法を教えていただけますか?

:heart: ありがとう!

Selection_839

「いいね!」 1

Discourse 2.8.0.beta4 (90232af778) を実行しているフォーラムで、DiscoTOC コンポーネントを含めるとエラーメッセージが表示されます。

oops

このコンポーネントは以前にも有効化されており、以前インストールされていた Discourse バージョンでも問題が発生していましたが、どのバージョンだったかは断言できません。

サイトのエラーログで、問題に関連するエラーメッセージは見つかりましたか?

そのエラーメッセージはバックエンドのエラーであり、DiscoTOCはフロントエンドのテーマコンポーネントなので、関連性は低いと思われます。何かプラグインをインストールしていますか?

「いいね!」 1

残念ながら、/logs には何も有用なものは見つかりませんでした。

はい、インストールしています。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

ヘッダーが引用符内にある場合、TOC(目次)に表示されません。この動作を変更することは可能でしょうか?

このヘッダーはTOCに表示されない

引用されたコンテンツ

このヘッダーはTOCに表示される

引用されたコンテンツ

どのように機能するように計画されているかはわかりませんが、通常はそうではありません。なぜなら、それは見出しではなく、引用の一部だからです。

「いいね!」 1

HTMLの<blockquote>を使ってみていただけますか?そうすれば、ヘッダーの#を行の先頭に配置できます。

例:

<blockquote>

### アンカーヘッダー

</blockquote>

アンカーヘッダー

目次(TOC)では試していませんが、通常の投稿での自動アンカーヘッダーでは機能するようです。

引用符内のヘッダーを目次 (TOC) に表示したいのはなぜですか?どのようなユースケースがありますか?

アイデアありがとうございます。しかし、私には機能しませんでした。

「Issue Area: Age」の下でコンテンツを視覚的に構成するために引用を使用する例を以下に示します。

「いいね!」 3

なぜ引用符をそのように使っているのですか?出典を伝えるだけで十分です。それに、英語でも文法的に間違っています。

これはバグですか、それとも単なる別のユーザーの行動ですか、しかし…目次を閉じるにはどうすればよいですか?エンドユーザーがプライベートメッセージをどのように使用すべきかについて、基本的な手順を探していたので、もちろん、新しいユーザーのドキュメントにアクセスし、情報があるかどうかを確認するために目次を開きました。

iPadとDiscourseHubを使用していました。

次のような表示になりました。

kuva

目次は問題ありません。しかし、テキストと重なってしまい、それを再び非表示にすることができませんでした。一体何が悪かったのか、あるいは何も悪くなかったのか :pleading_face: