# 按类别/标签批量应用目录

**URL:** https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323
**Category:** Feature
**Tags:** completed, disco-toc
**Created:** [2022年七月25日 07:54 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323 "2022-07-25T07:54:40Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![albert\_vu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert_vu/32/278482_2.png) [@albert\_vu](https://meta.discourse.org/u/albert_vu)
#### Post date: [2022年七月25日 07:54 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/1 "2022-07-25T07:54:40Z")

</div>

您好，我想知道是否有一种方法可以批量将目录应用于主题？我们最近刚安装了目录组件，现在必须手动将其应用于旧主题有点乏味 🥲

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年七月25日 09:02 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/2 "2022-07-25T09:02:20Z")

</div>

我会仔细检查，但我不认为这目前是可能的？不过我同情手动编辑。🙂 还有多少需要您完成？

---

<div class="post-metadata">

### Author: ![albert\_vu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert_vu/32/278482_2.png) [@albert\_vu](https://meta.discourse.org/u/albert_vu)
#### Post date: [2022年七月25日 09:15 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/3 "2022-07-25T09:15:01Z")

</div>

不过，我目前认为我们没有太多这样的功能，但如果团队能在未来的版本中考虑实现此功能，那就太好了 🤞

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年七月25日 17:57 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/4 "2022-07-25T17:57:25Z")

</div>

这是一个很棒的主意 @albert_vu，它已被采纳：🙂👍

> <https://github.com/discourse/DiscoTOC/pull/42>
>
> This PR adds two settings. 
> 
> One allows admins to select a list of categories …that will automatically enable the TOC if the topic category matches.
> The other does the same but with tags. 
> 
> Note that the topic still needs to have the other requirements for TOC, such as having headings. Also, this will still only apply to the first post.
> 
> This PR also moves some setting descriptions to the appropriate place. 
> 
> It also uses \`pretender\` for the tests instead of generating the fixture manually.

---

<div class="post-metadata">

### Author: ![albert\_vu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert_vu/32/278482_2.png) [@albert\_vu](https://meta.discourse.org/u/albert_vu)
#### Post date: [2022年七月26日 06:29 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/5 "2022-07-26T06:29:45Z")

</div>

太好了 😄 那么我需要从我这边更新主题组件吗？

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年七月26日 06:36 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/6 "2022-07-26T06:36:11Z")

</div>

如果您检查一下，您会发现它已经完成了。🙂👍

但对于任何想要炫酷新功能的人来说，您都可以从其自定义页面更新主题组件：

 ![update discotoc](https://global.discourse-cdn.com/meta/original/4X/0/d/c/0dce537eb9a4c6a42eb1571edb4168f2f1be801a.jpeg)

---

<div class="post-metadata">

### Author: ![albert\_vu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert_vu/32/278482_2.png) [@albert\_vu](https://meta.discourse.org/u/albert_vu)
#### Post date: [2022年七月26日 07:10 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/7 "2022-07-26T07:10:45Z")

</div>

嗯，我刚想到一个用户不希望在他们的主题中包含目录的场景，有没有办法撤销它？🤔

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年七月26日 07:14 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/8 "2022-07-26T07:14:42Z")

</div>

我喜欢它的标签元素，所以你可以有一个特定的标签用于目录，如果不需要的话，可以再次删除它？

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [2022年七月26日 07:41 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/9 "2022-07-26T07:41:56Z")

</div>

我喜欢自动化的想法，几乎在任何时间、任何地点。

我还没有更新 DiscoTOC，但如果它能移除工具栏中插入 TOC 的选项（当 TOC 来自类别时），那将是一个非常好的补充。就像锦上添花 😉

或者，做与 @albert_vu 所要求的相反的事情——提供一个选项来插入类似 `!toc` 的东西，如果你明白我的意思的话。

不过，对于普通用户来说，这可能会令人困惑。

我可以接受这一点，但当只有一个或两个标题时，TOC 几乎是不需要的。因为当有 TOC 时，一篇长文必须滚动到底部才能找出……用 Discourse 的术语来说……嗯，滚动日期的可能性。但我认为那是一个相当罕见的边缘情况。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2023年十月16日 07:26 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/10 "2023-10-16T07:26:11Z")

</div>

> [@Jagster](#):
>
> 我可以接受，但当只有一个或两个标题时，TOC 相当不必要。

有一个主题设置 `TOC min heading`（默认为 3），可以帮助解决这个问题。👍 这将抑制不满足最小要求的任何主题的目录。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2023年十月16日 07:26 UTC](https://meta.discourse.org/t/bulk-apply-tocs-by-category-tag/282323/11 "2023-10-16T07:26:36Z")

</div>


