> ## Documentation Index
> Fetch the complete documentation index at: https://www.notifuse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# テーマ

> Liquidテンプレートでブログの見た目をカスタマイズします。

![ブログのテーマエディター：テーマのファイル、コード、ライブプレビュー](https://www.notifuse.com/docs/assets/screenshots/theme_editor.png)

## テーマのファイル

各テーマは8つのファイルで構成されます。

| ファイル              | 用途             |
| ----------------- | -------------- |
| `home.liquid`     | ホームページのテンプレート  |
| `category.liquid` | カテゴリの一覧ページ     |
| `post.liquid`     | 個別の記事ページ       |
| `header.liquid`   | 共通のヘッダーパーシャル   |
| `footer.liquid`   | 共通のフッターパーシャル   |
| `shared.liquid`   | 再利用できるコンポーネント  |
| `styles.css`      | カスタムCSS        |
| `scripts.js`      | カスタムJavaScript |

## Liquidテンプレート

テーマは[Liquid](https://shopify.github.io/liquid/)のテンプレート構文を使います。

```liquid
<h1>{{ workspace.blog_title }}</h1>

{% for post in posts %}
  <article>
    <h2>{{ post.title }}</h2>
    <p>{{ post.excerpt }}</p>
  </article>
{% endfor %}
```

## 使える変数

### グローバル（全ページ）

```liquid
{{ workspace.id }}
{{ workspace.name }}
{{ workspace.blog_title }}
{{ workspace.logo_url }}
{{ workspace.icon_url }}
{{ base_url }}
{{ current_year }}
{{ theme.version }}
```

### カテゴリ

```liquid
{% for category in categories %}
  {{ category.id }}
  {{ category.slug }}
  {{ category.name }}
  {{ category.description }}
{% endfor %}
```

### 記事（ホームとカテゴリページ）

```liquid
{% for post in posts %}
  {{ post.id }}
  {{ post.slug }}
  {{ post.category_slug }}
  {{ post.title }}
  {{ post.excerpt }}
  {{ post.featured_image_url }}
  {{ post.published_at }}
  {{ post.reading_time_minutes }}

  {% for author in post.authors %}
    {{ author.name }}
    {{ author.avatar_url }}
  {% endfor %}
{% endfor %}
```

### 個別の記事（記事ページ）

```liquid
{{ post.title }}
{{ post.content }}
{{ post.excerpt }}
{{ post.featured_image_url }}
{{ post.published_at }}
{{ post.reading_time_minutes }}

{% for toc in post.table_of_contents %}
  {{ toc.id }}
  {{ toc.level }}
  {{ toc.text }}
{% endfor %}

{{ category.name }}
{{ category.slug }}
```

### ページネーション

```liquid
{{ pagination.current_page }}
{{ pagination.total_pages }}
{{ pagination.has_next }}
{{ pagination.has_previous }}
{{ pagination.total_count }}
{{ pagination.per_page }}
```

### ニュースレターのリスト

```liquid
{% for list in public_lists %}
  {{ list.id }}
  {{ list.name }}
  {{ list.description }}
{% endfor %}
```

## 便利なフィルター

| フィルター                  | 説明               | 例                                                                     |
| ---------------------- | ---------------- | --------------------------------------------------------------------- |
| `date`                 | 日付を整形            | `{{ post.published_at \| date: "%B %d, %Y" }}`                        |
| `truncate`             | 文字列の長さを制限        | `{{ post.excerpt \| truncate: 150 }}`                                 |
| `truncatewords`        | 単語数を制限           | `{{ post.excerpt \| truncatewords: 25 }}`                             |
| `upcase` / `downcase`  | 大文字・小文字を変換       | `{{ category.name \| upcase }}`                                       |
| `capitalize`           | 先頭の文字を大文字にする     | `{{ author.name \| capitalize }}`                                     |
| `strip_html`           | HTMLタグを除去        | `{{ post.content \| strip_html }}`                                    |
| `escape`               | HTMLエンティティをエスケープ | `{{ post.title \| escape }}`                                          |
| `url_encode`           | URL用にエンコード       | `{{ post.title \| url_encode }}`                                      |
| `default`              | 代替の値             | `{{ post.featured_image_url \| default: "/images/placeholder.jpg" }}` |
| `size`                 | 配列や文字列の長さ        | `{{ posts \| size }}`                                                 |
| `first` / `last`       | 最初や最後の要素を取得      | `{{ categories \| first }}`                                           |
| `sort`                 | 配列を並べ替え          | `{{ posts \| sort: "published_at" }}`                                 |
| `reverse`              | 配列を逆順にする         | `{{ posts \| reverse }}`                                              |
| `where`                | 配列を絞り込む          | `{{ posts \| where: "category_id", "news" }}`                         |
| `map`                  | プロパティを取り出す       | `{{ posts \| map: "title" }}`                                         |
| `join`                 | 配列の要素を連結         | `{{ post.tags \| join: ", " }}`                                       |
| `split`                | 文字列を分割           | `{{ "a,b,c" \| split: "," }}`                                         |
| `replace`              | テキストを置換          | `{{ post.title \| replace: "-", " " }}`                               |
| `append` / `prepend`   | 文字列に追加           | `{{ post.slug \| prepend: "/" }}`                                     |
| `plus` / `minus`       | 算術演算             | `{{ pagination.current_page \| plus: 1 }}`                            |
| `times` / `divided_by` | 算術演算             | `{{ post.reading_time_minutes \| times: 60 }}`                        |

## パーシャル

### Include（親のスコープを共有）

```liquid
{% include 'header' %}
{% include 'footer' %}
```

### Render（独立したスコープ）

```liquid
{% render 'shared', widget: 'newsletter' %}
{% render 'shared', widget: 'categories' %}
```

テンプレート名は引用符で囲む必要があります。Shopify Liquid 5.11と同じく、`{% render variable %}`と`{% snippet %}`には対応していません。テーマのLiquidはメールテンプレートと同じように動作し、[Shopify Liquidとの違い](https://www.notifuse.com/ja/docs/features/templates.md#differences-from-shopify-liquid)も同じです。

## テーマのバージョン管理

テーマはバージョンで管理されます。

![ブログテーマのバージョン：デフォルトテーマから作成したv2の下書きと、公開中のv1](https://www.notifuse.com/docs/assets/screenshots/theme_versions.png)

- 同時に公開できるバージョンは1つだけです
- 公開済みのバージョンは変わりません。編集を保存すると、新しい下書きバージョンが作成されます
- 下書きを保存すると、その下書きが更新されます
- 公開されていないバージョンは下書きです

## プレビューモード

公開前のテーマは、ブログの任意のURLに`?preview_theme_version=X`を付けるとプレビューできます。

```
https://blog.example.com/?preview_theme_version=5
https://blog.example.com/category/slug?preview_theme_version=5
```

プレビューはキャッシュを使わず、認証が必要です。
