# 在另一个网站中嵌入 Discourse 主题列表

**URL:** <https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911>\
**Category:** Announcements\
**Tags:** embedding\
**Created:** [2019年八月15日 17:53 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911 "2019-08-15T17:53:02Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![rosano](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rosano/32/219968_2.png) [@rosano](https://meta.discourse.org/u/rosano)\
**Post date:** [2021年五月12日 22:16 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/115 "2021-05-12T22:16:08Z")

</div>

可以修改哪些内容以指定多个类别？

---

<div class="post-metadata">

**Author:** ![alxndr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alxndr/32/102300_2.png) [@alxndr](https://meta.discourse.org/u/alxndr)\
**Post date:** [2021年五月19日 16:22 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/116 "2021-05-19T16:22:53Z")

</div>

当“其他站点”在本地 `http://localhost:8000` 运行，而 Discourse 站点位于非本地的 `https` 子域名上时，我是否应该期望它能正常工作？还是说“其他站点”也需要使用“真实”域名？

脚本文件似乎已成功获取，我在 JS 控制台中也未看到任何错误。“其他站点”是一个 Gatsby/React 站点；我在页面通过 `useEffect` 在浏览器中渲染后添加了 `<d-topics-list>` 元素，它在实时 DOM 中看起来是正确的（见截图）…

![Screen Shot 2021-05-19 at 9.21.08 AM](https://global.discourse-cdn.com/meta/original/3X/6/6/6655214e36b75ad637a71b2380f23132a5ee37bf.png)

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [2021年五月19日 18:28 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/117 "2021-05-19T18:28:26Z")

</div>

从 `https` 切换到 `http` 通常会导致问题，但你可以通过打开浏览器控制台 F12 来确认。

---

<div class="post-metadata">

**Author:** ![alxndr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alxndr/32/102300_2.png) [@alxndr](https://meta.discourse.org/u/alxndr)\
**Post date:** [2021年五月20日 00:52 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/118 "2021-05-20T00:52:02Z")

</div>

啊，我的问题似乎是 React 在干扰客户端 DOM，在 `embed-topics.js` 脚本插入 iframe 后立即将其重置为与服务端渲染的 DOM 一致（包含原始的 `<d-topics-list>` 元素）。

---

<div class="post-metadata">

**Author:** ![Vaping\_Community](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vaping_community/32/89248_2.png) [@Vaping\_Community](https://meta.discourse.org/u/Vaping_Community)\
**Post date:** [2021年八月2日 11:54 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/119 "2021-08-02T11:54:22Z")

</div>

有人知道这个错误是怎么回事吗？

最新的 Discourse 构建版本  
最新的 Chrome 浏览器

> 拒绝加载 ‘[https://vapingcommunity.co.uk/](https://vapingcommunity.co.uk/)’ 的框架，因为某个祖先元素违反了以下内容安全策略指令：“frame-ancestors ‘self’”。

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2021年八月2日 11:55 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/120 "2021-08-02T11:55:28Z")

</div>

很可能与此变更相关：(cc @falco)

> [@CSP Frame Ancestors enabled by default](https://meta.discourse.org/t/csp-frame-ancestors-enabled-by-default/197615?u=david):
>
> We just enabled the [Content-Security-Policy (CSP) frame-ancestors directive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors) by default on Discourse. By default it allows self and any domains allowed in Admin \> Customize \> Embedding. If necessary, a site administrator may disable it using the site setting content security policy frame ancestors, but that is not recommended.

您的主站是否已在“管理 \> 自定义 \> 嵌入”中注册？

---

<div class="post-metadata">

**Author:** ![Vaping\_Community](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vaping_community/32/89248_2.png) [@Vaping\_Community](https://meta.discourse.org/u/Vaping_Community)\
**Post date:** [2021年八月2日 11:56 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/121 "2021-08-02T11:56:44Z")

</div>

太棒了！没注意到那个改动，现在一切又完美运行了，非常感谢 😉

---

<div class="post-metadata">

**Author:** ![cokestroke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cokestroke/32/242007_2.png) [@cokestroke](https://meta.discourse.org/u/cokestroke)\
**Post date:** [2022年二月1日 21:56 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/122 "2022-02-01T21:56:19Z")

</div>

是否有人遇到“拒绝加载”错误？

我启用了嵌入式主题，但出现

```plaintext
拒绝加载“https://myforumurl.com/”，因为祖先违反了以下内容安全策略指令：“frame-ancestors 'self'”。

```

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2022年二月1日 22:04 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/123 "2022-02-01T22:04:30Z")

</div>

您是想将整个论坛嵌入到另一个网站吗？那行不通。

OP 描述了如何在另一个网站上嵌入主题列表，但由于您描述的原因，您无法在 iframe 中运行 Discourse。

---

<div class="post-metadata">

**Author:** ![cokestroke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cokestroke/32/242007_2.png) [@cokestroke](https://meta.discourse.org/u/cokestroke)\
**Post date:** [2022年二月1日 22:19 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/124 "2022-02-01T22:19:27Z")

</div>

只需要最新的主题。我已按照说明在设置中启用嵌入式主题，并将脚本复制到托管网站的标题和正文中。不确定错误是否是由于我正在测试的开发站点没有 SSL 引起的。

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2022年二月9日 10:14 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/125 "2022-02-09T10:14:16Z")

</div>

这是由于您网站上的安全设置，而不是 Discourse 方面的设置。

---

<div class="post-metadata">

**Author:** ![cokestroke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cokestroke/32/242007_2.png) [@cokestroke](https://meta.discourse.org/u/cokestroke)\
**Post date:** [2022年二月9日 12:46 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/126 "2022-02-09T12:46:33Z")

</div>

搞定了。只是没有仔细阅读说明书 🙂

---

<div class="post-metadata">

**Author:** ![stance455](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stance455/32/255345_2.png) [@stance455](https://meta.discourse.org/u/stance455)\
**Post date:** [2022年四月13日 15:19 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/127 "2022-04-13T15:19:20Z")

</div>

运行效果很好，我唯一的问题是谷歌正在索引 iframe 的 URL 本身

例如，我在[此页面](https://www.flynumber.com/products/virtual-phone-number/romania)上嵌入了 Discourse 主题

谷歌似乎能正常索引上面的页面……但它也索引了下面的 URL，我希望修复这个问题

[https://discuss.flynumber.com/embed/topics?discourse\_embed\_id=de-zse3f2nh3&template=complete&search=Romania&per\_page=5](https://discuss.flynumber.com/embed/topics?discourse_embed_id=de-zse3f2nh3&template=complete&search=Romania&per_page=5)

我们能否在上述页面上添加 meta noindex？或者更好的是，在上述页面上添加这个新的谷歌标签

> **[New robots tag: indexifembedded  |  Google Search Central Blog...](https://developers.google.com/search/blog/2022/01/robots-meta-tag-indexifembedded)**

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2022年四月18日 21:19 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/128 "2022-04-18T21:19:47Z")

</div>

谢谢你的建议@nader。我们应该默认将这个新标签添加到`<iframe>`中，@falco，还是将其设为一项设置？

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年四月18日 22:34 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/130 "2022-04-18T22:34:56Z")

</div>

这应该可以做到

> <https://github.com/discourse/discourse/pull/16495>
>
> This adds a robots tag header to disallow indexing the topic list that
> powers ou…r embed topic list feature. It also uses a new tag that allows
> the content to be indexed in the parent page.
> 
> See https://developers.google.com/search/blog/2022/01/robots-meta-tag-indexifembedded
> 
> https://meta.discourse.org/t/-/125911/127

---

<div class="post-metadata">

**Author:** ![stance455](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stance455/32/255345_2.png) [@stance455](https://meta.discourse.org/u/stance455)\
**Post date:** [2022年五月4日 17:11 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/131 "2022-05-04T17:11:03Z")

</div>

我只是想指出，它正在向所有爬虫提供“`noindex, indexifembedded`”，尽管只有谷歌[支持新的](https://developers.google.com/search/blog/2022/01/robots-meta-tag-indexifembedded) `indexifembedded`”。

这可能应该更改为 `x-robots-tag: googlebot:noindex, indexifembedded`。

或者完全删除，因为 noindex 可能对其他搜索引擎产生不可预见的后果。

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2022年五月9日 22:25 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/132 "2022-05-09T22:25:32Z")

</div>

我不认为多余的词对其他爬虫有特别大的危害。您有这方面的证据吗？例如，是否有其他爬虫告诉网站不要使用 `indexifembedded`？

（大多数时候，编写此类代码时，您会忽略任何您不期望的 HTML 标签，这在 HTML 中是默认行为。）

---

<div class="post-metadata">

**Author:** ![stance455](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stance455/32/255345_2.png) [@stance455](https://meta.discourse.org/u/stance455)\
**Post date:** [2022年五月10日 00:01 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/133 "2022-05-10T00:01:05Z")

</div>

> [@codinghorror](#):
>
> 例如，是否有其他爬虫告知网站不要使用 `indexifembedded`？

我没看到，但在[Google页面](https://developers.google.com/search/blog/2022/01/robots-meta-tag-indexifembedded)上确实提到：

> 目前，只有 Google 支持 `indexifembedded` 标签。

> [@codinghorror](#):
>
> （大多数时候，在编写此类代码时，您会忽略任何您不期望的 HTML 标签，这基本上是 HTML 的默认行为。）

我同意他们会忽略 `indexifembedded`，但我担心的是 `noindex` 会对页面本身的 SEO 产生影响。

所以，我们让 Bing 爬取一个包含主题嵌入的 URL。它会爬取该 URL，同时也会爬取嵌入 URL：

`/embed/topics?discourse_embed_id=XXXXXX....`

如果上述 URL 被设置为 `noindex`，我担心这会损害展示主题嵌入的页面的 SEO。

所有这些都可以通过使用 `x-robots-tag: googlebot:noindex, indexifembedded` 来解决，但我可以理解为什么 Discourse 可能不想偏袒一个搜索引擎。希望它能成为标准，但目前看来，它似乎只适用于 Google。

---

<div class="post-metadata">

**Author:** ![msbt](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/msbt/32/202927_2.png) [@msbt](https://meta.discourse.org/u/msbt)\
**Post date:** [2022年五月18日 09:02 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/134 "2022-05-18T09:02:15Z")

</div>

您好！只是想问一下，是否仍然没有内置方法可以让嵌入式主题像 `target="_blank"` 一样打开，而不是 `target="_parent"`？

---

<div class="post-metadata">

**Author:** ![Kane\_Thomas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kane_thomas/32/137561_2.png) [@Kane\_Thomas](https://meta.discourse.org/u/Kane_Thomas)\
**Post date:** [2022年五月19日 22:31 UTC](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911/135 "2022-05-19T22:31:36Z")

</div>

只是好奇为什么我只能看到一个主题？有人知道吗？

这是类别（其中有许多主题）：[Amazon Specific - eCommerce Sellers Forum](https://forum.flowster.app/c/amazon-specific/17)

这是嵌入代码：  
`<d-topics-list discourse-url="https://forum.flowster.app" template="complete" top_period="all" category="17" per-page="5"> </d-topics-list>`

但只出现一个主题：

 ![Selection_920](https://global.discourse-cdn.com/meta/original/4X/9/5/8/958a3ca3a35e117f0d0fbc640720cf0d7cca0bdf.png)

🤔

[上一頁](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911.md?page=3)

[下一頁](https://meta.discourse.org/t/embedding-a-list-of-discourse-topics-in-another-site/125911.md?page=5)
