安装 Discourse Theme CLI 命令行应用以帮助您构建主题

discourse Discourse 主题 CLI 是一个 ruby gem,它允许您在开发 Discourse 主题和主题组件时使用您选择的编辑器。当您保存文件时,CLI 将更新远程主题或组件,并且对它的更改将实时显示!

安装

要试用它,请确保您已安装 Ruby 2.5 或更高版本。

如果您使用的是 Windows,您有 2 个选择:

选项 1: 适用于 Linux 的 Windows 子系统

Windows 10 可以访问完整的 Linux 环境,您可以使用 sudo apt-get install ruby 简单地安装 ruby,这将为您提供 Ruby 2.3。

选项 2: 旧版 Windows

旧版 Windows 无法访问 WSL,您可以使用 Ruby Installer 轻松安装 Ruby,选择推荐的版本和默认的安装设置。

Mac OS 版本 10.13.3 预装了 Ruby 2.3,无需特殊操作。如果您运行的是早期版本的 Mac OS,请考虑使用 rvmrbenvhomebrew 来安装较新的 ruby。


一旦运行了 Ruby 2.2 或更高版本,请打开终端或命令提示符并运行:

gem install discourse_theme

安装后,要了解更多信息:

discourse_theme

升级

gem update discourse_theme

功能

CLI 提供 3 个主要功能:

discourse_theme new

您可以使用 discourse_theme new YOUR_DIR_NAME 快速创建一个新主题

discourse_theme watch

您可以使用它来监视一个主题并与 Discourse 站点(带有实时刷新)同步,使用 discourse_theme watch YOUR_DIR_NAME

这意味着您可以使用您自己的编辑器来编辑您的主题,站点将神奇地 :unicorn: 更新更改!

discourse_theme download

您可以使用 discourse_theme download YOUR_DIR_NAME 从 Discourse 下载现有主题。然后系统会询问您是否要立即开始“监视”!

凭证

您需要生成一个 API 密钥。转到管理区域并在那里生成一个密钥。

  • :exclamation: 生成密钥时,请选择“用户级别”为 Single User,而不是 All Users
  • :exclamation: 确保勾选 Global Key,否则您将收到 403 禁止访问错误。

凭证(可选)存储在 ~/.discourse_theme。API 密钥是按站点存储的,并且每个目录的 URL/theme_id 也会被跟踪。如果您需要更改设置,只需在任何命令后添加 --reset,系统将再次提示您输入所有值。

评价

“这个工具真是一个 GEM!” @awole20
“这非常好。” @awesomerobot
“它奏效了 :slight_smile: 而且它非常棒。太棒了!” @angus
“我的天哪。这太不可思议了。” @pfaffman


此文档是版本控制的 - 在 github 上建议更改。

79 个赞
Theme Creator, create and show themes without installing Discourse!
CSS Theme Contest (with Prizes!)
Customizing handlebars templates
Setting up a solid workflow for custom theme development
Theme Developer Quick Reference Guide
Structure of themes and theme components
Automating Discourse Plugin Setup with `create-discourse-plugin` gem
When exporting a theme, I get a broken archive
Install Discourse for development using Docker
Developing Plugins Faster by separating the frontend into a theme component
Feedback on "on-discourse" javascript for setting up custom JS for each page?
Add settings to your Discourse theme
Get started with Theme Creator and the Theme CLI
Designer's Guide to getting started with themes in Discourse
Split up theme Javascript into multiple files
Updated Custom Header Icon: Post Data via URL
Theme Developer Tutorial: 2. Creating a remote theme
Developing Discourse Themes & Theme Components
Hiding GUI elements for new users (less overwhelming)
Add custom content that only appears on your homepage
Custom CSS/HTML
[Zotero extension +] Firefox v116 on macOS broken Discourse?
Remote themes not in database
How "difficult" is modifying/extending Discourse for a backend dev
Exporting a Theme from Staging and Importing it to the Production portal
Using Plugin Outlet Connectors from a Theme or Plugin
Downloaded component installs fine, but does not once changed/re-zipped
What are the benefits of a dev environment?
3.2.0.beta2-dev (7019dbcfe1) does not load CSS from common.scss anymore
End-to-end system testing for themes and theme components
Different CSS changes for different color schemes
Need help integrating code wrote on Edittext to the Discourse
Need help integrating code wrote on Edittext to the Discourse
How to add a custom button in user profile card?
How to easily edit my site remotely?
When to use a plugin vs theme component?
Discourse core is switching to pnpm for JS package management
Using the new custom-homepage feature
Focus the editor when title is pre-filled
Cannot put the template in the desired outlet
Is this the correct way to create a theme component?
Split up theme Javascript into multiple files
Canvas Theme Template
If you want to edit this theme, you must submit a change on its repository
Import site theme via console
How are theme setting fields created?
Customisability in discourse?
Edit CSS/HTML editor cursor offset makes it unusable due to CSS font override
Discourse Theme CLI is the bomb
Discourse 2.0.0.beta5 Release Notes
How difficult would it be to make the Discourse UI more like Flarum?
Discourse-webpack: A boilerplate for developing JS-heavy Discourse components
Import Error: about.json does not exist, or is invalid
How to Add Unique HTML Content Below Topic Body in discourse forum for Specific Topics
Reuse Discourse Hamburger Functionality
Themes - Add a description field
Create and share a font theme component
Customisability in discourse?
How to create a theme (if I am a pure end user)
Linting configuration
Linting configuration
Is it possible to use a local plugin directory with a docker install?
How to overrule a color variable for one theme only?
Can't customize text on custom button in template override using UI
Is it possible to use theme component from local folder (as plugin) - for local development?
Restrict editing of remote themes

Admin > Customize > Themes 中的 Uploads 在保存了已关注的主题后消失。

我们如何将图像资源包含在主题中,以便在保存后不会被清除?

2 个赞

您好,欢迎!

您需要直接在主题组件中包含资源。
在根目录,创建一个 assets 目录。
然后,在 about.json 中声明它们

"assets": {
  "<your_identifier>": "assets/<your_asset_filename>",
}

您可以在此处看到一个示例 https://github.com/MeghnaAJ/discourse-christmas-decorations。

3 个赞

使用此工具生成主题组件的开发者请注意:

建议您升级它! :+1:

最近的 PRdiscourse-theme-skeleton 仓库设为默认模板。它将为您提供最新的配置文件!

9 个赞

谢谢!

在主题中添加一个“更新”部分会很棒……

是 --reset 还是 rubygem update?

4 个赞

好主意!我已将“升级”部分添加到 OP 中

gem update discourse_theme
5 个赞

要在WSL上安装gem,我必须运行sudo apt-get install rubysudo apt-get install ruby-dev。也许可以将这些添加到安装说明中。

如果你不安装 ruby-dev,是否会收到错误?安装 ruby-dev 应该不是必需的,因为 ruby 本身就足够了。

4 个赞

我相当确定我收到了一个错误提示我安装 ruby-dev,否则我不会知道这个包的存在。
但我尝试重新安装时却无法重现它。也许第一次的时候我做了什么奇怪的操作。

2 个赞

嗯,这确实很奇怪。如果您能再次重现问题,请随时告知我。

2 个赞

我昨天已将服务器更新到 3.5.0.beta9-dev,但自此 discourse 主题 gem 不再提供实时重新加载。Gem 版本为 2.1.6。

我没有看到任何错误等信息,所以想先问问是否有人遇到同样的问题?

2 个赞

样式表的实时重新加载已在生产实例中禁用,因为它们在更新主题和/或 Discourse 核心时会导致问题。

根本原因:样式表的更改通常与 JS/HTML 的更改相关联,因此仅对样式表进行实时加载存在风险。用户最终会使用“新”样式表针对“旧” HTML 进行操作,这可能导致一些非常奇怪的体验。

实时重新加载在开发模式的 Discourse 实例中仍然启用。理想情况下,您应该在开发环境中使用它,而不是生产站点。除了样式表重新加载之外,开发模式的 Ember 比生产模式的 Ember 提供更友好的错误消息。

3 个赞

这是一个很大的改变。我很惊讶竟然没有公告。我之前主要是在生产站点上进行主题开发。

也许可以添加一个站点设置来恢复旧的行为。

6 个赞

同意,这让我很惊讶,尽管搜索了,但我找不到这个当前的主题,或者我看到了旧的 OP 日期并忽略了它。

1 个赞

一篇帖子被拆分到新主题:如何恢复以前的主题