テーマ開発者クイックリファレンスガイド

テーマの機能が強化されるにつれて、その動作について覚えておくべき事項も増えていきます。#theme-guides タグには詳細なドキュメントが多数用意されていますが、記憶を呼び起こすためのヒントが必要であれば、このガイドが役立つでしょう。

一般的なリソース

:scroll: 初心者向けガイド
:scroll: デザイナー向けガイド
:scroll: 開発者向けガイド
:paintbrush: Theme Creator
:desktop_computer: Theme CLI
:notebook_with_decorative_cover: テーマディレクトリ
:jigsaw: コンポーネントディレクトリ
:wrench: Theme Modifiers
:wrench: テーマ対応サイト設定

ファイル/フォルダ構造 詳しくはこちら

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

:link: 利用可能な CSS 変数

Javascript 詳しくはこちら

// {theme}/javascripts/api-initializers/init-theme.gjs
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  // ここにコードを記述
});

:link: JS プラグイン API

:link: マルチファイル JavaScript

設定 詳しくはこちら

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 で行ってください。

「いいね!」 40