gpt4 book ai didi

html - Schema.org HTML 标记 : can I just use the meta tags?

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:43 27 4
gpt4 key购买 nike

所以我在查看 Schema.org。我需要更改我的 <html> 吗?标记为此

<html itemscope itemtype="http://schema.org/Article">

或者我可以只使用 <head></head> 中的元标记吗?阻止?

<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">

最佳答案

属性需要属于一个项目。您使用 itemscope 属性创建一个项目(itemtype 属性可以为该项目指定一个类型)。

没有 itemscope,您的标记示例无效。

可以只在 head 元素中提供微数据,但不推荐这样做,原因有二:

  • 微数据旨在用于您现有的标记。虽然在 head ( with itemref, see an example ) 中包含某些 meta/link 元素通常是有意义的,但大部分内容通常位于正文。如果您只想使用 head 中的元素,则必须复制大部分内容。但是如果你想走那条路,你might prefer to use JSON-LD .

  • 由于 head 不允许使用分组元素(如 div),因此表达微数据变得复杂。您将不得不为每个属性使用 itemref,并为每个项目滥用 style 等元素(参见 the first snippet in this answer 作为示例)。

您的示例可能如下所示:

<head>
<style itemscope itemtype="http://schema.org/Article" itemref="p1a p1b p1c"></style>
<meta id="p1a" itemprop="name" content="The Name or Title Here">
<meta id="p1b" itemprop="description" content="This is the page description">
<link id="p1c" itemprop="image" href="http://www.example.com/image.jpg">
</head>

如果可以在head元素上使用itemscope,那就更好了:

<head itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</head>

但是一旦您需要多个项目(这通常是这种情况,例如,对于 Organization/Person,即 author 等),这不再有效,您需要像我的第一个代码片段中那样的解决方案。

请注意,允许在 body 元素中为微数据使用 meta/link 元素。这使它变得更容易,因为您可以为 itemscope 使用 div 元素。因此,即使您复制内容而不是标记现有内容,最好在 body 中执行此操作:

<div itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</div>

(我用 link 元素替换了 image 属性的 meta 元素,因为 using meta is invalid for this purpose 。)

关于html - Schema.org <head> HTML 标记 : can I just use the meta tags?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46610201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com