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": "我的主题",
"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": {
"我的配色方案": {
"primary": "222222"
}
},
"screenshots": ["screenshots/light.jpeg", "screenshots/dark.jpeg"]
}
有关如何为主题添加设置的说明,请参阅:Add settings to your Discourse theme
如果您想添加的是主题组件而非完整主题,只需在 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 上提出修改建议。

