本文介绍了如何在聚合物中设置动态Meta标签和Open Graph标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个聚合物节点网站,我一直在研究,无法弄清楚如何包含动态元标记和Open Graph标记。 Jquery将无法工作,也不会使用聚合物api添加节点,因为它将在页面加载后添加所有标签,facebook将无法读取标签。 Google抓取工具会渲染页面,但最好是我可以在标题中设置说明。

I have a polymer node site that I've been working on and can't figure out how to include dynamic meta tags and Open Graph tags. Jquery won't work and neither will using the polymer api to add a node because it will add all the tags after the page loads and facebook won't be able to read the tags. Google crawlers do render the page but it would be best if I could set the description in the header.

<html>
  <head>
    <meta name="description" content="description goes here" />
    <meta property="og:title" content="title"/>
  </head>
  <body>
    <group-pages id="grouppages" is="dom-bind"></group-pages>
  </body>
</html>

grouppages设置数据并使用服务根据网址填充页面但我可以'找出是如何根据页面更改元标记。

grouppages sets the data and uses a services to populate the page based off the url but what I can't find out is how to change the meta tags depending on the page.

任何人都有任何想法?

一个想法是获取信息服务器端并将其发送到聚合物,但我仍然不确定节点和聚合物之间是否可能。

One thought was get information server side and send it in to polymer but I'm still not sure if that's possible between node and polymer.

推荐答案

如果您使用Firebase托管Polymer应用程序,则可以使用Firebase预渲染index.html文件功能。

If you host your Polymer app with Firebase, you can prerender the index.html file with a Firebase http trigger function.

exports.host = functions.https.onRequest((req, res) => {
  // replace og-tags in the index.html file and return it
});

参见了解更多信息。

这篇关于如何在聚合物中设置动态Meta标签和Open Graph标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 03:24