# 在帖子头部添加类似 meta、rel 的内容

**URL:** <https://meta.discourse.org/t/add-something-like-meta-rel-to-the-head-of-posts/150951>\
**Category:** Support\
**Created:** [2020年五月10日 10:02 UTC](https://meta.discourse.org/t/add-something-like-meta-rel-to-the-head-of-posts/150951 "2020-05-10T10:02:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)\
**Post date:** [2020年五月10日 10:02 UTC](https://meta.discourse.org/t/add-something-like-meta-rel-to-the-head-of-posts/150951/1 "2020-05-10T10:02:55Z")

</div>

真遗憾，但我已经为这个问题寻找解决方案长达 60 天了。所以希望您的专业知识能帮上忙。

这是关于此问题的第三个帖子，前两次被拒绝是因为认为不需要 Discourse 功能，需要重写整个系统等等……但我觉得这个需求是专门为某个网站定制的，因此一个插件应该能解决这个问题。

我在其他连接器中找到了一段代码，但在 `<head>` 和 `</head>` 之间没有找到任何相关指令。

**回到主要问题：**  
在帖子的 `<head>` 中添加以下内容：

`<link rel="amphtml" href="AMP-DOMAIN.LINK_POST"/>`

如果需要大量定制，可以将其移至付费请求部分。

这是之前的帖子：[Add rel="amphtml" to head - any tips?](https://meta.discourse.org/t/add-rel-amphtml-to-head-any-tips/143773)

每天都很焦虑，但老板仍然在问工作进展如何。

我同意这对 Discourse 来说可能不是最佳方案，但我个人需要尝试一下，看看实际效果如何！

如果使用 JavaScript 生成它，在 `view-source` 中无法显示，这意味着它需要在服务器端生成。

---

<div class="post-metadata">

**Author:** ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)\
**Post date:** [2020年五月10日 10:06 UTC](https://meta.discourse.org/t/add-something-like-meta-rel-to-the-head-of-posts/150951/2 "2020-05-10T10:06:56Z")

</div>

如果我使用 `app/views/connectors/topic_header/rel_amphtml.html.erb` 创建一个新的插件，它就会显示出来！实际上，插件中的每次更改都需要一些时间来重新运行服务器，因此服务器不应失败。

---

<div class="post-metadata">

**Author:** ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)\
**Post date:** [2020年五月27日 04:28 UTC](https://meta.discourse.org/t/add-something-like-meta-rel-to-the-head-of-posts/150951/3 "2020-05-27T04:28:52Z")

</div>

我已经创建了：

> <https://github.com/bcat95/discourse-tvms-amp/blob/master/app/views/connectors/topic_header/tvms_amp.html.erb>

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/7/07f42cb267bcb2cb6f4a7572f0b87ce33f66f541.png)

> 看起来 Google 仍然能够识别标签是在 body 中，而不是在 head 中。
