博客文章标签和类别的HTML5语义标记 [英] HTML5 semantic markup for blog post tags and categories

查看:239
本文介绍了博客文章标签和类别的HTML5语义标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多博客使用标签和类别的概念来向帖子添加元数据。这种信息的语义标记的最佳做法是什么,使阅读博客文章的机器可以轻松识别标签?



目前我将tag添加到 rel 属性,例如

 < a rel =tagclass =taghref =/ tags.html #位点配置>#站点的配置< / A> 

我想人们可以使用Dublin Core的html格式作为关键字:

 < meta name =DC.Subject
content =site-configuration>

并将其添加到页面标题中,或者可以将meta标签放入正文中?其中一个或另一个更可取,或者一些完全不同的选择?

在提供精确和标准化的内容定义方面,是否有更好的策略?

如果我想对元数据如此挑剔,或者应该使用XML文档类型,那么HTML5是合理的选择吗?



不同方法的优点和缺点是什么?

解决方案

第一步将在语义上正确获取/使用纯HTML。对于(X)HTML5,您应该使用分段内容元素节,抛开 nav ,并使用标题 footer 将元数据内容与主要内容分开;还要考虑内联级语义,如时间(发布日期), dfn (定义), abbr (缩写/首字母缩略词)等。并使用 meta - name rel 规范中定义的值。



第二步将是使用未在规范中定义但在指定位置注册的元数据属性值(因此它们可以使用),如 名称关键字元素 rel a / 区域 / 链接元素



第三步将是用语义机器可读注释来增强标记。有三种常用方法




  • 微格式(使用预定义的 rel 值)

  • RDFa(使用属性和URI)

  • Microdata(使用属性和URI)


RDFa和Microdata是相似的(既可扩展又相当复杂),而微格式更简单(但不具有很强的表达性/可扩展性)。我在程序员处写了一篇关于简短回答。 ://stackoverflow.com/a/25888436/1591669> Microdata和RDFa之间的差异。



对于RDFa或Microdata,您的主要工作将会找到能够描述/分类您的内容的词汇表/本体。这样的词汇可以由每个人创建(你甚至可以自己创建一个),但是通常使用知名/流行的词汇是可取的,例如搜索引擎可以使用你的注释(例如: Schema.org )。



在微格式的情况下,找到适合您需求的Microformat(位于 wiki的microformats.org )。如果你的情况没有,你可以提出一个新的Microformat(但这需要一段时间,直到它被接受,如果有的话)。





如果我想对元数据如此挑剔,或者我应该使用XML文档类型,HTML5是一个合理的选择吗?


如果您需要/需要XML支持,您也可以使用XHTML5。如果您仅使用规范中定义的(X)HTML而没有其他XML模式/词汇表,那么如果您使用HTML(5)或XHTML(5),则从语义角度来看无关紧要。


Many blogs use the concept of "tags" and "categories" to add metadata to a post. What is the best practice for semantic markup for this information, such that a machine reading the blog post could easily identify the tags?

Currently I add "tag" to the rel attribute on the link, e.g.

<a rel="tag" class="tag" href="/tags.html#site-configuration">#site-configuration</a>

I suppose one could use Dublin Core's html format for keyword:

<meta name = "DC.Subject"
          content = "site-configuration">

and add this to the page header, or can meta tags go in the body? Is one or the other preferable, or some entirely different option?

Is there a better strategy in terms of providing precise and standardized definitions for content?

Is HTML5 a reasonable choice if I want to be so picky about metadata, or should I be using an XML doctype?

What are the pros and cons of the different approaches?

解决方案

The first step would be to get/use the plain HTML semantically right. In case of (X)HTML5 you should build an appropriate outline using the sectioning content elements section, article, aside and nav, and use header and footer to separate the metadata content from the main content; also think of inline-level semantics like time (publication date), dfn (definitions), abbr (abbreviations/acronyms) etc. And make use of meta-name and rel values that are defined in the spec.

The second step would be to make use of metadata attribute values that are not defined in the specification, but are registered at specified places (so they are valid to use), like name keywords for meta elements and rel values for a/area/link elements.

The third step would be to enhance the markup with semantic, machine-readable annotations. There are three common ways to do this:

  • Microformats (using pre-defined class and rel values)
  • RDFa (using attributes and URIs)
  • Microdata (using attributes and URIs)

RDFa and Microdata are similar (both extensible and rather complex), while Microformats is simpler (but not so expressive/extensible). I wrote a short answer over at Programmers about the differences, and more detailed answer about the differences between Microdata and RDFa.

In the case of RDFa or Microdata, your main job would be to find vocabularies/ontologies that are able to describe/classify your content. Such vocabularies can be created by everyone (you could even create one yourself), but it's often advisable to use well-known/popular ones, for example so that search engines can make use of your annotations (popular example: Schema.org).

In the case of Microformats, you'd have to find a Microformat (on the wiki at microformats.org) that suits your needs. If there is none for your case, you could propose a new Microformat (but that would take some time until it gets "accepted", if at all).


Is HTML5 a reasonable choice if I want to be so picky about metadata, or should I be using an XML doctype?

You could also use XHTML5, if you need/want XML support. If you "only" use the (X)HTML defined in the specification and no additional XML schemas/vocabularies, it won't matter from a semantic perspective if you use HTML(5) or XHTML(5).

这篇关于博客文章标签和类别的HTML5语义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆