在第一部分中,使用rel来定义基于链接的关系
在第二部分中,使用XFN微格式为链接增加人际关系的描述
在第三部分中,使用hCard微格式来描述人、公司和地点
还不错。但是距离全面介绍微格式还有一定差距呢。
所以,今天让我们一起来探讨一下hCalendar微格式,通过该微格式我可以为那些关于事件和基于时间或地点的活动提供语义和结构化信息。
来源:iCalendar
iCalendar(或者iCal)是分享日历数据的标准。通常的,他被广泛用在Email交换中,虽然并不仅仅局限于此。同hCard类似,网站开发人员可以通过hCalendar将iCalendar数据嵌入到网页数据中。hCalendar同iCalendar之间同样是1:11:11:1的对应关系,从而允许解析器从网页中提取信息提供给日历应用使用。1:11:11:1的对应关系,从而允许解析器从网页中提取信息提供给日历应用使用。
历史回顾:iCalendar建立在vCalendar(虚拟日历Virtual Calendar)基础之上,vCalendar是一个开源的日历应用,用来在线发布和维护事件和时刻表。vCalendar同vCard电子商务名片格式一起开发的。
基于日期/时间的活动
hCalendar微格式描述在日历中使用的事件(或者任何基于日期/时间的活动)信息,包括(但不限于):
- 概述
- 日期和时间
- 地点
- 详细描述
- 重复发生
基础知识
跟hCard一样,hCalendar遵循一些基本规则:
- 属性和子属性通过class来描述。
- 因为跟iCalendar之间1:1的对应关系,特定的hCalendar属性是建立在iCalendar属性名称基础上的(例如,vevent)
- 属性和子属性名字大小写敏感
- “根”属性不能同其他属性组合。因此<p class="vevent summary">是无效的。
还有一条虽然不是规则,但是需要铭记在心:使用什么样的标记元素并不重要。class的值(属性/子属性)才决定hCalendar微格式。但之前也说过,我非常鼓励使用具有语义特性的标记元素。
Profile
同所有微格式一样,非常鼓励您在网页的<head>部分中包含微格式的声明,使用hCalendar的Profile:
<head profile=”http://purl.org/uF/hCalendar/1.0/”>
W3C允许定义多个Profile值,使用空格隔开,所以可以自己选择使用多个Profile:
<head profile="http://gmpg.org/xfn/11 http://purl.org/uF/hCard/1.0/ http://purl.org/uF/hCalendar/1.0/“>
另外,如果您引用非提案微格式(hCalendar是非提案微格式),您可以替换使用组合Profile URL,该URL涵盖了所有非提案微格式:
<head profile="http://purl.org/uF/2008/03/“>
如果您同时引用非提案和提案微格式,您同样可以使用上面这条组合Profile声明。
示例
本博客相对比较新,因此,我还没有更多的机会列举一些事件信息。实际上,我只有一个在线的例子,感谢最近一篇BarCamp Albuquerque 3的文章,在那里我使用了hCalendar微格式:
- <div class=”vevent”>
- <p>Yes, it's short notice, but mark your calendars: <a href="http://barcamp.org/BarCampAlbuquerque" class=”url summary”><span class=”category”>BarCamp</span> Albuquerque 3</a> is this weekend.</p>
- <dl>
- <dt>When:</dt>
- <dd><abbr class=”dtstart” title=”2008-09-13T09:00:00″>September 13</abbr>–<abbr class=”dtend” title=”2008-09-14T18:00:00″>14</abbr>, from 9am–6pm both days</dd>
- <dt>Where:</dt>
- <dd class=”location vcard”><a class=”fn org url” href=”http://www.chefwhite.com/cjw_cafe.php”>CJW Cafe</a> on <a href=”http://maps.google.com/maps” class=”adr”><span class=”street-address”>4801 Alameda <abbr title=”Boulevard”>Blvd</abbr> <abbr title=”Northeast”>NE</abbr></span>, <span class=”locality”>Albuquerque</span>, <abbr class=”region” title=”New Mexico”>NM</abbr> <span class=”postal-code”>87113</span></a></dd>
- <dt>What:</dt>
- <dd class=”description”>A <abbr class=”duration” title=”P2D”>two-day</abbr> event all about the web — design (visual, experience, information architecture), technology (infrastructure, programming), social and new media, and other stuff that is just plain cool.</dd>
- </dl>
- </div>
说说各部分
我们将上面的例子分开讨论一下。
“根”:vevent
您可能注意到在我例子中的根属性是vevent,而不是vcalendar。这是因为hCalendar有一个可选的根元素,只有在您需要在页面中描述超过一个日历事件时才需要出现。对于尽有一个日历事件的网页,vcalendar属性被假设已经出现在页面中。既然我的例子只是一个事件,我把所有的事件信息都包含在<div class="vevent">中,意味着所有的内容描述的都是同一个事件。
包含他的元素可以是任何元素(<dl>,<ul>,<p>,<span>等等)。<div>就满足我例子的要求了。
必要属性:summary和dtstart
hCalendar必须的属性为(除了根元素vevent)summary和dtstart.
summary
summary属性描述了事件的概要信息。此属性包含的内容通常是在日历应用中显示的基本信息,比如事件的名称。所以,在我的例子中,“BarCamp Albuquerque 3”被包含在summary之中,也就是在我个人日历中用来显示的名称:
<p>Yes, it's short notice, but mark your calendars: <a href="htt