是否可以使用`itemscope =“false”itemtype =“false”`来指定没有结构化数据的页面?

时间:2013-07-30 20:14:26

标签: html5 pug semantic-markup schema.org structured-data

我刚开始使用schema.org元标记突出显示我网站上的结构化数据。

我正在使用node.js,express和jade来生成我的内容。我在一些但不是所有页面上设置这些标签。我不想将未标记的页面误传给搜索引擎。

我还没有找到一种优雅的方法来仅将itemscope属性插入到我的html文档中。

编辑 - @martinhepp建议将属性字符串传递给Jade并将其插入标记内。我想这样做,但我不知道怎么做。这是我的尝试和输出。

//node.js
locals.testSchemaTag = 'itemscope itemtype="http://schema.org/Product"';
//jade
p(locals.testSchemaTag) Foo Bar
//rendered HTML
<p locals.testschematag="">Foo Bar</p>

这样会更好。但是,如果这不起作用或没有人知道如何操作,对于我不想指定特定模式的页面,将itemscope设置为false就足够了吗?

这就是我现在正在做的事情。

// node.js
res.locals.schema = res.locals.schema || { 
  itemtype: "false", 
  itemscope: "false", 
  properties: [], 
};         
if(res.locals.schema.itemtype !== "false"){
  res.locals.schema.itemscope = "itemscope";
  res.locals.schema.properties = res.locals.schema.properties || []; 
};   

// jade
!!!
html(itemscope=locals.schema.itemscope, itemtype=locals.schema.itemtype)
  head

// rendered output A
<html itemscope="itemscope" itemtype="http://schema.org/Restaurant">

// rendered output B
<html itemscope="false" itemtype="false">

这会让搜索引擎感到困惑,还是他们会认识到我在这里禁用了itemscope元素的itemtype<html>属性?

2 个答案:

答案 0 :(得分:1)

首先:我假设您所谈论的内容都发生在服务器端。任何客户端Javascript都不适用于主流搜索引擎抓取工具,仅适用于未来支持schema.org的浏览器扩展。

现在,简单的答案是:如果要在某些情况下禁止标记,只需在itemscope和itemtype关键字周围添加条件子句。

// rendered output A
<html itemscope="itemscope" itemtype="http://schema.org/Restaurant">

// rendered output B
<html>

就是这样。

另请注意,在大多数情况下,html元素是schema.org类型的错误位置。对于schema:WebPage,使用head元素。对于schema:Product,schema:Offer等,使用模板体e.h中的相应元素。 h1,div,article,section,...

马丁

答案 1 :(得分:1)

我为Yandex(yandex.ru/.com - 俄罗斯最受欢迎的搜索引擎)工作,可以告诉我们如何处理它。我打赌,虽然每个SE的过程都是相同的。

这里应该考虑三件事。

1。Microdata W3C doc

  

指定了itemscope属性的元素会创建一个新项目,   一组名称 - 值对。

即如果您将 itemscope 属性放在HTML元素中,它将被视为项目。即使在你的情况下(事实上“= false”被忽略)。如果您不想定义新项目,则根本不应使用 itemscope 属性。

2.使用标记的每个搜索引擎都有自己的验证工具 - 仪器,您可以在其中专门检查此SE的标记处理。对于Yandex,它是here,因为Google是here。 Bing也有一个,但它首先需要在他们的网站管理员工具中使用登录。将它用于您关于partucular SE的标记处理的每个问题,您将获得非常详细的答案。

所以你没有提供标记的例子,但让我们考虑一下这个简单的例子。

<div itemscope="false" itemtype="false">
  <span itemprop="name">Not a happy camper</span> -
  by <span itemprop="author">Ellie</span>,
  <meta itemprop="datePublished" content="2011-04-01">April 1, 2011
  <span itemprop="description">The lamp burned out and now I have to replace it. </span>
</div>

所以Yandex的验证员说:

microdata
  WARNING: itemtype false not recognized by validator
  itemType = false
    name = Not a happy camper
    author = Ellie
    datepublished = 2011-04-01
    description = The lamp burned out and now I have to replace it.

如您所见,itemscope =“false”被忽略,项目类型设置为“false”(由于itemtype =“false”)。那就是Yandex发现了一些实体但却不知道该怎么做(更多关于第三点的内容)。

Google怎么样?

Item 
  property: 
  name: Not a happy camper
  author:   Ellie
  datepublished:    2011-04-01
  description:  The lamp burned out and now I have to replace it.

几乎相同,只是它将实体视为没有类型。

3.但事实上你不应该真的关心这个:)没有任何搜索引擎可以使用完整的词汇表及其所有类型(schema.org,微格式或任何其他类型)。这就是每个搜索引擎都有它理解并拥有产品的类型列表。对于Yandex列表为here,对于Google为here,对于Bing为here。正如您所看到的,支持非常有限,但正在积极发展。这究竟意味着什么?即使您的“虚假”标记被视为对象,它实际上也不会在任何地方使用。所以你可以安全地做到这一点:)