简体   繁体   English

我应该使用哪个 HTML5 标签来标记作者的姓名?

[英]Which HTML5 tag should I use to mark up an author’s name?

For example of a blog-post or article.例如博客文章或文章。

<article>
<h1>header<h1>
<time>09-02-2011</time>
<author>John</author>
My article....
</article>

The author tag doesn't exist though... So what is the commonly used HTML5 tag for authors?虽然author标签不存在... 那么作者常用的 HTML5 标签是什么? Thanks.谢谢。

(If there isn't, shouldn't there be one?) (如果没有,不应该有一个吗?)

Both rel="author" and <address> are designed for this exact purpose. rel="author"<address>都是为此目的而设计的。 Both are supported in HTML5. HTML5 支持两者。 The spec tells us that rel="author" can be used on <link> <a> , and <area> elements.规范告诉我们rel="author"可以用在<link> <a><area>元素上。 Google also recommends its usage . Google 还推荐了它的用法 Combining use of <address> and rel="author" seems optimal.结合使用<address>rel="author"似乎是最佳的。 HTML5 best affords wrapping <article> headlines and bylines info in a <header> like so: HTML5 最适合将<article>标题和署名信息包装在<header>如下所示:

<article>
    <header>
        <h1 class="headline">Headline</h1>
        <div class="byline">
            <address class="author">By <a rel="author" href="/author/john-doe">John Doe</a></address> 
            on <time pubdate datetime="2011-08-28" title="August 28th, 2011">8/28/11</time>
        </div>
    </header>

    <div class="article-content">
    ...
    </div>
</article>
  • The pubdate attribute indicates that that is the published date. pubdate属性表明这是发布日期。

  • The title attributes are optional flyovers. title属性是可选的天桥。

  • The byline info can alternatively be wrapped in a <footer> within an <article>署名信息也可以包含在<article>中的<footer>

If you want to add the hcard microformat , then I would do so like this:如果你想添加hcard microformat ,那么我会这样做:

<article>
    <header>
        <h1 class="headline">Headline</h1>
        <div class="byline vcard">
            <address class="author">By <a rel="author" class="url fn n" href="/author/john-doe">John Doe</a></address> 
            on <time pubdate datetime="2011-08-28" title="August 28th, 2011">on 8/28/11</time>
        </div>
    </header>

    <div class="article-content">
    ...
    </div>
</article>

HTML5 has an author link type : HTML5 有一个作者链接类型

<a href="http://johnsplace.com" rel="author">John</a>

The weakness here is that it needs to be on some sort of link, but if you have that there's a long discussion of alternatives here .这里的弱点是它需要在某种链接上,但如果你有,这里有一个 关于替代方案长时间讨论 If you don't have a link, then just use a class attribute, that's what it's for:如果您没有链接,则只需使用类属性,这就是它的用途:

<span class="author">John</span>

According to the HTML5 spec, you probably want address .根据 HTML5 规范,您可能需要address

The address element represents the contact information for its nearest article or body element ancestor.地址元素表示其最近的文章或正文元素祖先的联系信息。

The spec further references address in respect to authors here该规范进一步参考了关于作者的address here

Under 4.4.4根据 4.4.4

Author information associated with an article element (qv the address element) does not apply to nested article elements.与文章元素(qv 地址元素)相关联的作者信息不适用于嵌套的文章元素。

Under 4.4.9根据 4.4.9

Contact information for the author or editor of a section belongs in an address element, possibly itself inside a footer.某个部分的作者或编辑的联系信息属于地址元素,它本身可能位于页脚内。

All of which makes it seems that address is the best tag for this info.所有这些都使得address似乎是此信息的最佳标签。

That said, you could also give your address a rel or class of author .也就是说,你也可以给你的address一个relauthor class

<address class="author">Jason Gennaro</address>

Read more: http://dev.w3.org/html5/spec/sections.html#the-address-element阅读更多: http : //dev.w3.org/html5/spec/sections.html#the-address-element

In HTML5 we can use some semantic labels that help organize the information regarding your type of content, but additional and related to the subject you can check schema.org .在 HTML5 中,我们可以使用一些语义标签来帮助组织有关您的内容类型的信息,但您可以查看与主题相关的附加信息schema.org It is an initiative of Google, Bing and Yahoo that aims to help search engines to better understand websites through microdata attributes.这是谷歌、必应和雅虎的一项倡议,旨在通过微数据属性帮助搜索引擎更好地理解网站。 Your post could look like this:您的帖子可能如下所示:

<article itemscope itemtype="http://schema.org/Article">
<header>
  <h1 itemprop="headline">header</h1>
  <time itemprop="dateCreated datePublished">09-02-2011</time>
  <div itemprop="author publisher" itemscope itemtype="http://schema.org/Organization">
    <p>
        <img itemprop="image logo" src="..."/>
        <span itemprop="name">John</span>
    </p>
  </div>
</header>
<section itemprop="articleBody" >
    My article....
    <img itemprop="image" src="..."/>
</section>
</article>

Google support for rel="author" is deprecated :不推荐使用Google 对 rel="author" 的支持:

"Authorship markup is no longer supported in web search." “网络搜索不再支持作者标记。”

Use a Description List (Definition List in HTML 4.01) element.使用描述列表(HTML 4.01 中的定义列表)元素。

From theHTML5 spec :HTML5 规范

The dl element represents an association list consisting of zero or more name-value groups (a description list). dl 元素表示由零个或多个名称-值组(描述列表)组成的关联列表。 A name-value group consists of one or more names (dt elements) followed by one or more values (dd elements), ignoring any nodes other than dt and dd elements.名称-值组由一个或多个名称(dt 元素)后跟一个或多个值(dd 元素)组成,忽略除 dt 和 dd 元素之外的任何节点。 Within a single dl element, there should not be more than one dt element for each name.在单个 dl 元素中,每个名称的 dt 元素不应超过一个。

Name-value groups may be terms and definitions, metadata topics and values, questions and answers, or any other groups of name-value data.名称-值组可以是术语和定义、元数据主题和值、问题和答案,或任何其他名称-值数据组。

Authorship and other article meta information fits perfectly into this key:value pair structure:作者和其他文章元信息完全适合这个键:值对结构:

  • who is the author谁是作者
  • date the article published文章发表日期
  • site structure under which the article is organized (category/tag: string/arrays)组织文章的站点结构(类别/标签:字符串/数组)
  • etc.等等。

An opinionated example:一个固执的例子:

<article>
  <header>
    <h1>Article Title</h1>
    <p class="subtitle">Subtitle</p>
    <dl class="dateline">
      <dt>Author:</dt>
      <dd>Remy Schrader</dd>
      <dt>All posts by author:</dt>
      <dd><a href="http://www.blog.net/authors/remy-schrader/">Link</a></dd>
      <dt>Contact:</dt>
      <dd><a mailto="remy@blog.net"><img src="email-sprite.png"></a></dd>
    </dl>
  </header>
  <section class="content">
    <!-- article content goes here -->
  </section>
</article>

As you can see when using the <dl> element for article meta information, we are free to wrap <address> , <a> and even <img> tags in <dt> and/or <dd> tags according to the nature of the content and it's intended function .正如您在使用<dl>元素获取文章元信息时所见,我们可以根据内容的性质将<address><a>甚至<img>标签包装在<dt>和/或<dd>标签中内容及其预期功能
The <dl> , <dt> and <dd> tags are free to do their job -- semantically -- conveying information about the parent <article> ; <dl><dt><dd>标签可以自由地完成它们的工作——语义上——传达关于父<article> <a> , <img> and <address> are similarly free to do their job -- again, semantically -- conveying information regarding where to find related content, non-verbal visual presentation, and contact details for authoritative parties, respectively. <a><img><address>类似地可以自由地完成他们的工作——同样,在语义上——分别传达有关在哪里可以找到相关内容、非语言视觉呈现和权威方的联系方式的信息。

You can use您可以使用

<meta name="author" content="John Doe">

in the header as per the HTML5 specification .根据HTML5 规范在标头中。

If you were including contact details for the author, then the <address> tag is appropriate:如果您包含作者的联系方式,则<address>标签是合适的:

But if it's literally just the author's name, there isn't a specific tag for that.但如果它实际上只是作者的名字,则没有特定的标签。 HTML doesn't include much related to people. HTML 没有包含太多与人相关的内容。

How about microdata : 微数据怎么样:

<article>
<h1>header<h1>
<time>09-02-2011</time>
<div id="john" itemscope itemtype="http://microformats.org/profile/hcard">
 <h2 itemprop="fn">
  <span itemprop="n" itemscope>
   <span itemprop="given-name">John</span>
  </span>
 </h2>
</div>
My article....
</article>

You may use meta tag for this purpose, as follows:为此,您可以使用元标记,如下所示:

 <head> <meta name="author" content="red bot"> </head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM