随着主题功能日益强大,关于其工作原理需要记忆的内容也越来越多。我们在 #theme-guides 下提供了详尽的文档,但如果你只需要一些内容来唤起记忆,本指南可能会有所帮助。
通用资源
新手指南
设计师指南
开发者指南
主题创建器
主题命令行工具
主题目录
组件目录
主题修饰符
可主题化的站点设置
文件/文件夹结构 了解更多
about.json
settings.yml
common/, desktop/, mobile/
{common|desktop|mobile}.scss
head_tag.html
header.html
after_header.html
body_tag.html
footer.html
embedded.scss (仅限 common)
locales/
en.yml
...
assets/
(任意命名的文件,在 about.json 中引用)
stylesheets/
(任意命名的文件,可相互导入,也可被 common/desktop/mobile.scss 导入)
javascripts/
(任意命名的文件。支持 .js、.gjs 和 .hbs)
about.json 结构信息,可用元数据
{
"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"
}
}
}
SCSS
JavaScript 了解更多
// {theme}/javascripts/api-initializers/init-theme.gjs
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
// 你的代码
});
设置 了解更多
settings.yml:
fruit:
default: apples|oranges
type: list
description: # 旧方法。最好在语言文件中定义这些内容(见下文)
en: English Description
fr: Description Française
在 JavaScript 中访问:
console.log(settings.fruit);
在 gjs 模板中访问:
<template>{{settings.fruit}}</template>
在 scss 中访问:
html {
font-size: #{$global-font-size}px;
background: $site-background;
}
可主题化的站点设置 了解更多
about.json:
"theme_site_settings": {
"enable_welcome_banner": false
}
在 JavaScript 中访问:
@service siteSettings;
this.siteSettings.enable_welcome_banner;
在 gjs 模板中访问:
<template>{{this.siteSettings.enable_welcome_banner}}</template>
翻译 了解更多
locales/en.yml
en:
my_translation_key: "I love themes"
theme_metadata: # 这些内容用于管理面板。它们不会在你的 js/hbs 文件中提供
description: This theme lets you do amazing things on your Discourse
settings:
fruit: A description of the whitelisted_fruits setting
在 JavaScript 中访问:
import { i18n } from "discourse-i18n";
i18n(themePrefix("my_translation_key"));
在 gjs 模板中访问:
import { i18n } from "discourse-i18n";
<template>
{{i18n (themePrefix "my_translation_key")}}
<DButton @label={{theme-prefix "my_translation_key"}} />
</template>
本文档受版本控制——请在 github 上提出修改建议。