# 为什么我觉得 Discourse 很难自定义？

**URL:** https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671
**Category:** Development
**Created:** [2024年四月13日 13:51 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671 "2024-04-13T13:51:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![P\_O](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p_o/32/343333_2.png) [@P\_O](https://meta.discourse.org/u/P_O)
#### Post date: [2024年四月13日 13:51 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/1 "2024-04-13T13:51:37Z")

</div>

如果我想编辑 CSS，我必须创建一个组件，创建一个 CSS 文件，然后它就能正常工作。现在，如果我添加另一个组件，例如“Discourse Topic Cards”，然后返回自定义 CSS 文件，应用更改，单击保存，然后刷新页面，自定义 CSS 就不会生效。

另外，为什么在管理员区域没有编辑模板的方法？如果我想编辑“Discourse Topic Cards”模板，我必须 SSH 进入 discourse docker 并进行编辑才能进行更改？

---

<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: [2024年四月13日 13:58 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/2 "2024-04-13T13:58:36Z")

</div>

您对 WordPress 更熟悉吗？如果熟悉，您会更容易理解这一点：您永远不要直接编辑核心、插件或主题，因为下次更新时您将丢失所有修改。

因此，许多这些困难实际上并非来自 Discourse，而是来自世界的运作方式 😏

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年四月13日 14:43 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/3 "2024-04-13T14:43:17Z")

</div>

> [@P\_O](#):
>
> 应用更改，点击保存，然后刷新页面，自定义 CSS 不会生效。

您可能需要将 `!important` 添加到 CSS 中，以便这些规则优先于其他地方定义的规则。当多个组件按特定顺序加载时，就会出现这种情况。这是一个常见问题，不一定特定于 Discourse。我不知道我们是否可以有一个权重系统来指示“_该组件应最后加载_”，但这听起来确实难以管理。

这就是为什么主题和主题组件不使用 CSS 中的 `!important` 很重要，除非绝对必要。

> [@P\_O](#):
>
> 如果我想编辑‘Discourse Topic Cards’模板

如果您想编辑远程主题组件，请随时在 GitHub 上分叉它并创建您自己的版本。这是最简单的方法！但是，您将不会收到原始版本的任何更新。您无法编辑远程组件，因为您的自定义可能会与更新发生冲突（并且处理起来很麻烦）。

> [@P\_O](#):
>
> 为什么在管理区域没有编辑模板的方法

自定义 Discourse 非常容易。但这取决于您期望的自定义程度。您在这里想实现什么？也许我们可以提供帮助。如果某个领域欢迎自定义功能，Discourse 团队通常会持开放态度。

---

<div class="post-metadata">

### Author: ![P\_O](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p_o/32/343333_2.png) [@P\_O](https://meta.discourse.org/u/P_O)
#### Post date: [2024年四月13日 15:17 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/4 "2024-04-13T15:17:18Z")

</div>

我经营网站已经很多年了，我认为如果你能创造出更独特的东西，往往会做得更好。我想自定义“Discourse Cards Topic”模板，并在通用主题列表中包含海报、回复、浏览量和活跃度统计数据。

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年四月13日 15:51 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/5 "2024-04-13T15:51:31Z")

</div>

> [@P\_O](#):
>
> 我想自定义“Discourse Cards Topic”模板，并在通用主题列表中包含海报、回复、浏览量和活动统计信息。

您可以：

- 请求功能（在相关主题中，就像您刚才做的那样）
- 如果可以，请在 #Marketplace 发布
- 学习如何编码以及主题组件的工作原理（请参阅 #documentation:theme-developers），如有任何帮助，请随时向 #Dev 提问！

---

<div class="post-metadata">

### Author: ![P\_O](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p_o/32/343333_2.png) [@P\_O](https://meta.discourse.org/u/P_O)
#### Post date: [2024年四月13日 19:05 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/6 "2024-04-13T19:05:24Z")

</div>

有供编码人员阅读的文档吗？

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年四月13日 19:21 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/7 "2024-04-13T19:21:08Z")

</div>

以下是一些您可能会感兴趣的、用于熟悉 Discourse 的资源：

> [@Beginner's guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966):
>
> This is a crash course in Discourse theme basics. The target audience is everyone who is not familiar with Discourse themes. If you’ve already used Discourse theme / theme components, this guide is probably not something you need to read. What are themes and theme components? A theme or theme component is a set of files packaged together designed to either modify Discourse visually or to add new features. Let’s start with themes. Themes In general, themes are not supposed to be compatible …

> [@Developing Discourse Themes & Theme Components](https://meta.discourse.org/t/beginners-guide-to-developing-discourse-themes/93648):
>
> Discourse Themes and Theme Components can be used to customize the look, feel and functionality of Discourse’s frontend. This section of the developer guides aims to provide all the reference materials you need to develop simple themes for a single site, right up to complex open-source theme components. This introduction aims to provide a map of all the tools and APIs for theme development. If you prefer a step-by-step tutorial for theme development, jump straight to: Themes vs. Theme Compon…

> [@Theme Developer Quick Reference Guide](https://meta.discourse.org/t/theme-developer-quick-reference-guide/110448):
>
> As themes grow more powerful, there’s more to remember about how they work. We have loads of detailed documentation under [#howto / #themes](https://meta.discourse.org/tags/c/howto/themes), but if you just need something to jog your memory, this guide may help. General Resources [scroll Beginner’s guide](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966)[scroll Designer’s guide](https://meta.discourse.org/t/designers-guide-to-discourse-themes/152002/1)[scroll Developer’s guide](https://meta.discourse.org/t/developer-s-guide-to-discourse-themes/93648)[paintbrush Theme Creator](http://theme-creator.discourse.org)[desktop_computer Theme CLI](https://meta.discourse.org/t/discourse-theme-cli-console-app-to-help-you-build-themes/82950)[notebook_with_decorative_cover Theme Directory](https://meta.discourse.org/c/theme)[jigsaw Component Directory](https://meta.discourse.org/c/theme-component)[wrench Theme Modifiers](https://meta.discourse.org/t/theme-modifiers-a-brief-introduction/150605)[wrench Themeable site…](https://meta.discourse.org/t/-/374376)

请慢慢阅读！有些指南也包含指向外部指南的链接。

如果您有疑问，请询问 #Dev 👍 。

---

<div class="post-metadata">

### Author: ![traceymoko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/traceymoko/32/483235_2.png) [@traceymoko](https://meta.discourse.org/u/traceymoko)
#### Post date: [2024年四月14日 07:01 UTC](https://meta.discourse.org/t/why-am-i-finding-discourse-so-difficult-to-customize/303671/8 "2024-04-14T07:01:11Z")

</div>

> [@P\_O](#):
>
> 现在，如果我添加另一个组件，例如“Discourse Topic Cards”，然后返回自定义 CSS 文件，应用更改，单击保存，然后刷新页面，自定义 CSS 将不会应用。

> [@P\_O](#):
>
> 如果我想编辑“Discourse Topic Cards”模板，我必须 SSH 进入 discourse docker 并编辑什么才能进行更改？

如果您想在 Discourse Topic Cards 主题组件之上进行更改，可以这样做：

1. 安装 Discourse Topic Cards 并将其添加到您的活动主题中
2. 创建一个新的主题组件
3. 将新主题组件也添加到活动主题中

您不必 SSH 进入服务器或更改源代码中的任何内容，也不必分叉存储库。

例如，这是我为 Minima 主题对 Discourse Topic Cards 进行一些更改所做的工作：

> [@bloomexperiment](#):
>
> ## 说明
> 
> 1. 安装 [Discourse Minima](https://meta.discourse.org/t/minima-a-minimal-theme-for-discourse/108178)
> 2. 安装 [Discourse Topic Cards](https://meta.discourse.org/t/discourse-topic-cards/296048) 并将其添加为 Discourse Minima 的主题组件
> 3. 安装此主题组件并将其添加为 Discourse Minima 的主题组件

这样，您仍然可以从主题中获取新更新，并且所有主题组件都经过组织和分离（因此您可以轻松禁用/启用以进行调试）

但是的，我认为这个过程可以为管理员解释得更好一些。
