Skip to content

ARCHIVED

!注意“归档”

This chapter has not been updated for the current version of Orchard, and has been ARCHIVED.

Orchard will provide an easy way for content type authors to expose new feeds and advertise them from a view.

Orchard将为内容类型作者提供一种简单的方法来公开新的供稿并从视图中公布它们。

Requirements

要求

  • Feeds should strictly conform to the relevant standards.

  • 饲料应严格遵守相关标准。 *

  • Any list of content items can be exposed as a feed.

  • 任何内容项列表都可以作为Feed公开。 *

  • It is simple as possible to enable feeds on a list of contents, no matter what the type of content item is.

  • 无论内容项的类型是什么,尽可能简单地在内容列表上启用馈送。 *

  • Feeds should be able to contain heterogeneous content types.

  • Feed应该能够包含异构内容类型。 *

  • Feed contents should be easily extensible (for example by content parts).

  • 饲料内容应易于扩展(例如通过内容部分)。 *

Feed rendering and why it's not just a view

Feed渲染以及为什么它不仅仅是一个视图

When rendering an HTML page, there are potentially going to be multiple content items and multiple parts for each item, all contributing to the rendering. But whereas in HTML the rendering for each part are relatively isolated from each other, in the case of a feed, the contribution actually happens on the same tag. In other words, in HTML, each aspect results in an island of HTML that it owns, whereas in RSS, everyone parties on the same tags, and there is only one tag (and subtags) for each item.

渲染HTML页面时,每个项目可能会有多个内容项和多个部分,这些都有助于渲染。但是在HTML中,每个部分的渲染彼此相对隔离,在Feed的情况下,贡献实际上发生在同一个标​​记上。换句话说,在HTML中,每个方面都会产生它拥有的HTML岛,而在RSS中,每个方都在相同的标签上,并且每个项目只有一个标签(和子标签)。

Template-based rendering of XML does not provide significant benefits and in fact obscures the design. For example, if you want to let different (and unknown) parts of a content item contribute attributes to the top-level item element, you would need to inject a zone placeholder inside of the item tag.

基于模板的XML渲染不会带来显着的好处,实际上也掩盖了设计。例如,如果要让内容项的不同(和未知)部分向顶级项元素提供属性,则需要在item标记内注入区域占位符。

XML manipulation APIs are mature and will enable much cleaner construction of the feed documents from many parts than the regular view template system would allow. The template system would end up generating XML fragment strings from C# code.

XML操作API已经成熟,与常规视图模板系统允许的许多部分相比,可以更轻松地构建源文档。模板系统最终将从C#代码生成XML片段字符串。

The target audience for building handlers that contribute to feeds is also different as HTML templates are usually written by designers whereas feed handlers will be written by content type or part authors, who are developers.

构建对提要有贡献的处理程序的目标受众也不同,因为HTML模板通常由设计者编写,而提要处理程序将由内容类型或部分作者(即开发人员)编写。

Exposing contents as a feed

将内容公开为Feed

Orchard will provide a ready-made controller for RSS, Atom and other feeds. This controller will dispatch the request to registered feed handlers, providing them a context object. Each handler can decide whether to handle the request or not based on the information available on the context object. If it decides to handle the request, it can add feed items to the response object (a property of the context object).

Orchard将为RSS,Atom和其他feed提供现成的控制器。该控制器将请求发送到已注册的Feed处理程序,为它们提供上下文对象。每个处理程序可以根据上下文对象上可用的信息决定是否处理请求。如果它决定处理请求,它可以将feed项添加到响应对象(上下文对象的属性)。

Multiple handlers can independently contribute to a given feed, allowing for example the home page feed of a site to include items from a blogging module, a pages module and a forum module.

多个处理程序可以独立地对给定的馈送做出贡献,例如允许站点的主页馈送包括来自博客模块,页面模块和论坛模块的项目。

Building a feed document from the list of feed items

从Feed项列表构建Feed文档

The way the feed document is built is specific per feed type (RSS, Atom, etc.) and per content part. Feed item builder objects will be able to contribute to the document based on the feed item and the type of feed.

构建订阅源文档的方式特定于每种订阅源类型(RSS,Atom等)和每个内容部分。 Feed项目构建器对象将能够根据Feed项目和Feed类型为文档做出贡献。

Advertising a feed from a view

从视图广告Feed

To be discoverable, feeds have to be advertised on the regular views that show the same data in HTML form. This advertising can be done as actual links in the HTML body, and as link tags in the header. The latter is the most important as it enables feed readers to discover the feeds automatically. The former is important to inform user who may not be aware of feeds.

要发现,必须在以HTML格式显示相同数据的常规视图上公布Feed。此广告可以作为HTML正文中的实际链接以及标题中的链接标记来完成。后者是最重要的,因为它使饲料阅读器能够自动发现饲料。前者对于通知可能不了解Feed的用户非常重要。

The code that advertises a feed will be written in the display template for a specific container item. For example, the post feed for a blog will be advertised from the display template for the Blog object that also displays the list of posts.

广告Feed的代码将写入特定容器项的显示模板中。例如,博客的帖子提要将从Blog对象的显示模板中公布,该对象也显示帖子列表。

The link tag advertising is done by calling Html.RegisterFeed(new {type="comment", parent=slug}, "Comment feed");. From that, Orchard will ask each feed provider (we will provide RSS and Atom) to create a link tag that will get added to the top-level zone subsection "header:link" (need to add that subsection to the existing styles and scripts).

链接标记广告是通过调用Html.RegisterFeed(new {type =“comment”,parent = slug},“Comment feed”);来完成的。从那时起,Orchard将要求每个提要提供者(我们将提供RSS和Atom)来创建一个链接标记,该链接标记将被添加到顶级区域子节“header:link”(需要将该子节添加到现有样式和脚本中) )。

To advertise the feed as an HTML link, a developer can call a Html.FeedLink helper. That helper, modeled after Html.ActionLink, creates a specialized A tag that already has the type="application/rss+xml" attribute and builds the URL to the feed.

要将Feed作为HTML链接公布,开发人员可以调用Html.FeedLink帮助程序。在Html.ActionLink之后建模的帮助器创建了一个专门的A标签,该标签已经具有type =“application / rss + xml”属性并构建了feed的URL。

A variation is to handle the whole markup from the view template and only get the URL from the Html.FeedUrl helper for maximum control over the link markup. It should be pointed out that this may make it more difficult down the road to easily modify how RSS links get rendered throughout the site. Because of that, we might want to introduce a display template for feeds that Html.FeedLink can use when it exists.

一种变体是从视图模板处理整个标记,并且只从Html.FeedUrl帮助程序获取URL以最大程度地控制链接标记。应该指出的是,这可能会使得在整个站点中轻松修改RSS链接的呈现方式变得更加困难。因此,我们可能希望为Html.FeedLink存在时可以使用的Feed引入显示模板。

Feed advertising could be automatically done on all content item containers. This way, feeds would become automatically available for all lists of contents without any specific development. Enabling finer-grained configuration of feed availability could be added later.

可以在所有内容项容器上自动完成Feed广告。这样,在没有任何特定开发的情况下,所有内容列表将自动提供订阅源。稍后可以添加更精细的饲料可用性配置。

Lifecycle of a feed

饲料的生命周期

  • On a blog post page

  • 在博客文章页面上 *

    • Html.RegisterFeed(new {type="comment", parent=slug}, "Comment feed"); results in .
  • Navigating to that feed url is routed to the feed controller

  • 导航到该Feed网址将路由到Feed控制器 *

    • controller retrieves the IEnumeration

    • foreach IFeedHandler in the list, Invoke(FeedContext). FeedContext has a Request property that has route values and querystring.

*** The Invoke code contributes to ctx.Response.FeedItems (FeedItem has ContentItem and XElement, which is null for now).

** Invoke代码对ctx.Response.FeedItems有贡献(FeedItem有ContentItem和XElement,现在为null)。

*** controller gets the IEnumeration (there is one for each feed format: RSS, Atom, etc. and IFeedBuilder has a Format string property).

** controller获取IEnumeration (每个feed格式有一个:RSS,Atom等,IFeedBuilder有一个Format字符串属性)。

*** find the IFeedBuilder for the current format and call Invoke(FeedContext) on it. FeedContext has a Format string property so each IFeedBuilder can decide to participate. It also has an XDocument on the Response (null so far). The Invoke code creates the XDocument on context.Response if it doesn't exist and populates its top-level properties.

** 找到当前格式的IFeedBuilder并在其上调用Invoke(FeedContext)。 FeedContext具有Format字符串属性,因此每个IFeedBuilder都可以决定参与。它在Response上也有一个XDocument(到目前为止为null)。 Invoke代码在context.Response上创建XDocument(如果它不存在)并填充其顶级属性。

*** foreach FeedItem in context.Response.FeedItems, create the XElement on the FeedItem

** foreach FeedItem在context.Response.FeedItems中,在FeedItem上创建XElement

*** foreach IFeedItemBuilder, Invoke(FeedContext, IFeedBuilder)

** foreach IFeedItemBuilder,Invoke(FeedContext,IFeedBuilder)

**** The feed builder invocation enumerates foreach FeedItem and maps ContentItem to XElement as appropriate when the format is recognized, or dumps data by calling back into IFeedBuilder.AddProperty(string name, string value, FeedItem). The feed builder can then choose to format that data in a generic way or throw the data away.

** 在识别格式时,Feed构建器调用枚举foreach FeedItem并将ContentItem映射到XElement,或者通过回调到IFeedBuilder.AddProperty(字符串名称,字符串值,FeedItem)来转储数据。然后,Feed构建器可以选择以通用方式格式化该数据或抛弃数据。

*** The XDocument is now complete. The feed builder returns an ActionResult.

** XDocument现已完成。 Feed构建器返回ActionResult。

* The controller returns the ActionResult it got back from the feed handler.
  • ActionResult gets executed, resulting in an XML string, a JSON string or even possibly it could be injected into the view engine if a "regular" ActionResult was returned.

  • ActionResult被执行,导致XML字符串,JSON字符串,甚至可能在返回“常规”ActionResult时注入到视图引擎中。 *

Object model

对象模型

FeedContext

FeedContext

  • FeedRequest Request {get;set;}

  • FeedRequest Request {get; set;} *

  • FeedResponse Response {get;set;}

  • FeedResponse响应{get; set;} *

FeedRequest

FeedRequest

  • RouteData RouteData {get;}

  • RouteData RouteData {get;} *

  • HttpRequestBase HttpRequest {get;}

  • HttpRequestBase HttpRequest {get;} *

FeedResponse

FeedResponse

  • XDocument Document {get;set;}

  • XDocument文档{get; set;} *

  • IEnumerable {get;}

  • IEnumerable {get;} *

FeedItem

FeedItem

  • ContentItem ContentItem {get;set;}

  • ContentItem ContentItem {get; set;} *

  • XElement Element {get;set;}

  • XElement元素{get; set;} *

IFeedHandler

IFeedHandler

  • void Invoke(FeedContext context)

  • void Invoke(FeedContext context) *

IFeedBuilder

IFeedBuilder

  • string Format {get;}

  • string格式{get;} *

  • ActionResult Invoke(FeedContext context)

  • ActionResult Invoke(FeedContext context) *

  • void AddProperty(string name, string value, FeedItem item)

  • void AddProperty(字符串名称,字符串值,FeedItem项) *

IFeedItemBuilder

IFeedItemBuilder

  • void Invoke(FeedContext context, IFeedBuilder feedBuilder)

  • void Invoke(FeedContext context,IFeedBuilder feedBuilder) *