【问题标题】:Suggestions for <head> tags for MeteorMeteor 的 <head> 标签建议
【发布时间】:2015-07-10 10:13:55
【问题描述】:

Meteor 用户,

在搜索教程和示例应用程序的过程中,我发现了一个使用独特的头部结构的:

  <meta charset="utf-8">
  <title>Title</title>
  <meta name="description" content="Top10">
  <meta name="viewport" content="width=device-width" />
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1">

这个特定的示例应用程序在任何地方都没有&lt;body&gt; 标签,只有一个名为head.html 的文件,其中包含上述代码。我还了解到,Meteor 似乎只是自动为您制作了一个 body 标签,所以从技术上讲,只需一个 head.html 就可以了。

所以,这让我想知道,是否有人为 Meteor 应用程序定义了特定的头部标签?理由是什么?上面的代码是一个好的起点吗?

【问题讨论】:

    标签: html meteor


    【解决方案1】:

    当 Meteor 解析您的各种 html 文件时,任何在 &lt;template&gt;&lt;/template&gt; 之外包含 &lt;head&gt;&lt;/head&gt; 标记的文件都将在您应用的每个页面中连接在一起成为一个 &lt;head&gt;&lt;/head&gt; 标记。这适用于包含标题、各种元标记和您希望在每个页面上使用的第 3 方资源等内容。然而,Meteor 中仍然不存在对标题标签的车把支持,因此它绝对限制了你可以用它做什么(没有动态元信息)。

    最后,如果你想要动态信息,你将不得不求助于 jquery 之类的东西

    您可以在这里找到更多围绕&lt;head&gt; 标签的讨论:

    https://github.com/meteor/meteor/issues/266

    【讨论】:

      【解决方案2】:

      您可以使用 iron:router 轻松设置动态标题,例如:

      onAfterAction: function(){
        document.title = 'my awesome site: ' + Router.current().route.getName();
      }
      

      我使用包含各种 SEO 设置的 head.html:

      <head>
      <meta name="viewport" content="width=device-width, initial-scale=1"/>
      <meta name="fragment" content="!"/>
      <meta name="description" content="your description"/>
      <meta property="og:title" content="your site title"/>
      <meta property="og:type" content="website"/>
      <meta property="og:image" content="https://yourimageurl"/>
      <meta property="og:url" content="https://hostname"/>
      <meta property="og:description" content="your description"/>
      <meta name="twitter:card" content="summary"/>
      <meta name="twitter:url" content="https://hostname"/>
      <meta name="twitter:title" content="your site title"/>
      <meta name="twitter:description" content="your site description"/>
      <meta name="twitter:image" content="https://yourimageurl">
      <noscript>You must have Javascript enabled in order to use this site</noscript>
      <link rel="shortcut icon" href="/your-ico" type="image/x-icon" />
      </head>
      

      【讨论】:

        【解决方案3】:

        查看https://github.com/kadirahq/meteor-dochead,我找到了一种将数据动态添加到&lt;head&gt;标签的方法

        var meta = '<div>just an example</div>' document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', meta);
        或者,如果您需要更多功能,只需添加该软件包

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-22
          • 1970-01-01
          • 2016-03-22
          • 2016-05-06
          • 2017-11-29
          • 1970-01-01
          相关资源
          最近更新 更多