Discourse 支持原生主题,可以从 .tar.gz 归档文件或远程 git 仓库(包括私有仓库)中获取。
一个主题示例位于:GitHub - discourse/discourse-simple-theme: Sam's simple discourse theme · GitHub
Git 仓库将检查更新(每天一次),或者通过使用 检查更新 按钮进行。当检测到更改时,检查更新 按钮将变为 更新到最新版本。
![]()
要创建主题,您需要遵循特定的文件结构。您可以包含以下文件:
about.json (必需)
common/common.scss
common/header.html
common/after_header.html
common/footer.html
common/head_tag.html
common/body_tag.html
common/embedded.scss
desktop/desktop.scss
desktop/header.html
desktop/after_header.html
desktop/footer.html
desktop/head_tag.html
desktop/body_tag.html
mobile/mobile.scss
mobile/header.html
mobile/after_header.html
mobile/footer.html
mobile/head_tag.html
mobile/body_tag.html
locales/en.yml
locales/{locale}.yml
stylesheets/{anything}/{anything}/{anything}.scss
javascripts/{anything}.js
javascripts/{anything}.gjs
javascripts/{anything}.hbs
assets/{asset_filename}
settings.yml
上述文件
均为可选,因此您只需创建所需的文件。
对于那些希望将主题 SCSS 拆分为多个文件的人来说,现在这是可行的。
对于那些希望将主题拆分为多个 JS 文件的人来说,只需将您想要的 JS 文件添加到 javascripts 目录中即可。
about.json 文件的结构如下,您可以在 Adding metadata and screenshots to a Theme 查看更多相关信息:
{
"name": "My Theme",
"component": false,
"license_url": null,
"about_url": null,
"authors": null,
"theme_version": null,
"minimum_discourse_version": null,
"maximum_discourse_version": null,
"assets": {
"variable-name": "assets/my-asset.jpg"
},
"color_schemes": {
"My Color Scheme": {
"primary": "222222"
}
},
"screenshots": ["screenshots/light.jpeg", "screenshots/dark.jpeg"]
}
有关如何为主题添加设置的说明,请参见此处:Add settings to your Discourse theme.
要告诉 Discourse 您将要添加的是一个主题组件而不是完整主题,只需在 about.json 文件中添加一行 "component": true
文件结构与主题自定义 CSS / HTML 相匹配。
延伸阅读
查看带有 #themes::tag 标签的其他文章。
另请参阅:
- Developing Discourse Themes & Theme Components
- Install the Discourse Theme CLI console app to help you build themes
- Include assets (e.g. images, fonts) in themes and components
最后由 @SaraDev 于 2022-08-15T21:00:00Z 审核
本文档受版本控制 - 建议修改请提交至 github。

