plone微数据支持核心包
collective.microdata.core的Python项目详细描述
目录
Introduction
本产品旨在为plone内容添加microdata支持。
How to use
这个包只是提供了原始的支持,对他自己并不是很有用。它的目的是 由希望为plone提供微数据支持的第三方项目扩展。
下面所有指令的一个完整实现是collective.microdata.event。
The microdata vocabulary
想要提供微数据信息的每种内容类型都需要为 IMicrodataVocabulary接口。此接口仅限于一个信息:一个uri 微型数据词汇表。
微数据词汇表在HTML5规范之外是标准化的,因此 不同语系的词汇。你也可以自己发明。
The schema.org implementation
现在最有前途的微数据实现是在schema.org定义的,所以 包裹支持它。这是通过提供定义的最泛型类型来完成的:类型Thing。
对于所有plone内容类型和catalog对象(对于catalog:a new 目录元数据microdata_itemtype将添加到您的目录中,保存最多 找到特定的微数据词汇url)。
这就完成了为ISchemaOrgThing接口(扩展IMicrodataVocabulary)提供适配器的工作。
再说一遍:知道所有的plone内容类型都是“things”不是很有趣,也不是一个真正的步骤 向前地。
How to extend
From contents
要从内容类型获取微数据信息,您的产品必须为 IMicrodataVocabulary:
<adapter for="your.products.content.IType" provides="collective.microdata.core.interfaces.IMicrodataVocabulary" factory=".adapter.YourTypeMicrodataProvider" />
然后您需要提供适配器:
class YourTypeMicrodataProvider(object): implements(IYourMicrodataVocabulary) def __init__(self, content): self.microdata_vocabulary = 'http://your.microdata.uri' # now get data from the content self.microdata_data1 = ...
然后,您的内容视图必须获得您定义的微数据适配器:
class YourTypeView(BrowserView): ... def microdata(self): return IMicrodataVocabulary(self.context)
最后,视图模板必须使用微数据信息:
... <article metal:fill-slot="main" tal:define="microdata view/microdata" itemscope="itemscope" tal:attributes="itemtype microdata/microdata_vocabulary"> ...
From catalog
门户目录microdata_itemtype列将自动存储内容微数据 词汇url。默认值是“thing”url(http://schema.org/Thing),但是只要 提供一个更具体的适配器,此url将替换为新的适配器。
有一个适配器可以从目录大脑中从所有plone内容获取原始的Thingmicrodata 类型,但您的第三方内容类型还必须提供更具体的类型:
<adapter for="Products.ZCatalog.interfaces.ICatalogBrain" provides="collective.microdata.core.interfaces.IMicrodataVocabulary" factory=".adapter.YourTypeMicrodataBrainProvider" name="http://your.microdata.uri" />
然后您需要提供适配器:
class YourTypeMicrodataBrainProvider(object): implements(IYourMicrodataVocabulary) def __init__(self, brain): self.microdata_vocabulary = 'http://your.microdata.uri' # now get data from the cataloged content self.microdata_data1 = ...
Support for folder content listing views
如果您还想在文件夹内容视图中提供微数据信息(因此显示多个 microdata对象在一个页面中),您可以安装collective.microdata.contentlisting。
有关如何在产品中使用此功能的详细信息,请参阅文档。
Testing your microdata
该产品还包括一个名为Microdata Tool的javascript测试器微数据工具。 (一个修改过的,只是为了修正一些糟糕的sunburst css规则)。
要在测试站点时启用它,只需从以下位置运行testinggeneric setup profile 你的站点设置工具。
这将在每个页面中启用javascript测试程序。
提示:持续时间检查程序似乎工作不正常。
Final notes
提供微数据并不能保证搜索引擎会使用它。