---
title: "コメントを埋め込む"
description: "HTML、静的サイト、CMS に接続します。同じサイトキーとページキーで同じスレッドを表示できます。"
---

> Documentation Index
> Fetch the complete documentation index at: https://blua.pwp.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# コメントを埋め込む

## 三つの値を用意する

- `endpoint` はブラウザーからアクセスできる Blua ゲートウェイです。例の `https://blua.example` を自分のアドレスに置き換えます。
- **設定 → サイト** で `site-key` を作成します。記事サイトのオリジンを 1 行に一つずつ登録します。
- `page-key` は記事の識別子です。タイトルやクエリ、翻訳 URL が変わっても一定の ID を使います。言語ごとにスレッドを分けたい場合は別々のキーを割り当てます。

## HTML

```html
<script type="module" src="https://blua.example/embed.js"></script>
<blua-comments
  endpoint="https://blua.example"
  site-key="garden"
  page-key="spring-swallows"
  locale="ja"
></blua-comments>
```

モジュールを各ページで一度読み込み、コメント欄を表示したい場所に要素を置きます。クライアント側で記事を切り替えたら `page-key` も更新します。コンポーネントと SSR の例は[フレームワーク連携](/docs/embed/frameworks)にあります。

## iframe

CMS の HTML または iframe ブロックには、ゲートウェイの `/embed` ページを指定します。`referrerpolicy="origin"` により埋め込み元を検証できます。

```html
<iframe
  id="discussion"
  title="記事のコメント"
  src="https://blua.example/embed?siteKey=garden&amp;pageKey=spring-swallows&amp;locale=ja"
  referrerpolicy="origin"
  loading="lazy"
  height="640"
  style="width: 100%; border: 0"
></iframe>
```

固定高では iframe 内をスクロールできます。モジュールスクリプトが使える場合は付属のヘルパーで高さを自動調整できます。SPA で iframe を取り外す際は戻り値のクリーンアップ関数を呼びます。

```html
<script type="module">
  import { connectBluaFrame } from 'https://blua.example/embed/host.js';
  const disconnect = connectBluaFrame(document.querySelector('#discussion'));
</script>
```

埋め込み元がリファラーを削除する場合は、登録済みの `parentOrigin` を URL エンコードして iframe の URL に追加します。親ページの `frame-src` にゲートウェイを許可します。

Source: https://blua.pwp.sh/docs/ja/embed/
