Feeds and Sitemap
MapOsirionFeeds maps three endpoints built from the published content of your content providers: an XML sitemap
at /sitemap.xml, an RSS 2.0 feed at /feed.xml and an Atom 1.0 feed at /atom.xml. Search engines read the
sitemap; feed readers subscribe to either feed. These are endpoints, not components, so this page has no demo and no
parameter table.
Package Osirion.Blazor.Cms.Web, namespace Osirion.Blazor.Cms.Web.Feeds. Source on GitHub. Available from 4.0.
Usage
Call it in Program.cs after the content services are registered:
using Osirion.Blazor.Cms.Web.Feeds;
app.MapOsirionFeeds(feeds =>
{
feeds.SiteUrl = "https://example.com";
feeds.FeedDirectory = "blog";
feeds.AdditionalSitemapUrls = ["/", "/blog"];
});
With no arguments, app.MapOsirionFeeds() maps all three endpoints over all content and builds URLs from the
request.
| Path | Format | Content |
|---|---|---|
/sitemap.xml |
sitemaps.org XML sitemap | AdditionalSitemapUrls, then every published item (the first 50,000 items a provider returns) |
/feed.xml |
RSS 2.0 | The newest FeedItemCount items by creation date, within FeedDirectory and FeedLocale |
/atom.xml |
Atom 1.0 | The same items as the RSS feed |
Configuration
OsirionFeedOptions has these properties:
| Property | Type | Default | Description |
|---|---|---|---|
SiteUrl |
string? |
null |
Public address used for every absolute URL, for example https://example.com. When empty, Osirion:Seo:SiteUrl is used (from the release after 4.1.0), and when that is empty too, the request's scheme, host and path base. |
Title |
string? |
null |
Feed title; otherwise the SEO SiteName, then the host name. |
Description |
string? |
null |
Feed description; otherwise the SEO SiteDescription, then the title. |
FeedDirectory |
string? |
null |
Directory the feeds cover, for example blog; all content when empty. |
FeedLocale |
string? |
null |
Locale the feeds cover, for example en; every locale when empty. Also written as the RSS language. |
FeedItemCount |
int |
20 |
How many of the newest items the feeds list. |
AdditionalSitemapUrls |
IList<string> |
empty | Paths that are not content items but belong in the sitemap, such as / or /blog. |
ContentUrlFormatter |
Func<ContentItem, string>? |
null |
Builds an item's path or absolute URL; default /{item.Url}. |
CacheDuration |
TimeSpan |
10 minutes | Cache-Control: public, max-age of every response. |
EnableSitemap |
bool |
true |
Maps /sitemap.xml. |
EnableRss |
bool |
true |
Maps /feed.xml. |
EnableAtom |
bool |
true |
Maps /atom.xml. |
The options are checked when MapOsirionFeeds runs: a SiteUrl that is not an absolute http or https URL
throws ArgumentException, and a FeedItemCount below 1 throws ArgumentOutOfRangeException, so a bad value stops
the application at startup instead of producing broken feeds.
What goes into each document
- Sitemap. Each URL has a
lastmodfrom the item'slast_modifiedfront matter, then, with the file system provider andFileSystemOptions.UseFileWriteTimeAsLastModifiedturned on (it is off by default), the file's write time, then the item's creation date: itsdatefront matter, or for a file the file's creation time. Setlast_modifiedwhen dates must survive a fresh checkout or a new deployment. Items whoseseo_properties.robotscontainsnoindexare left out, and duplicate URLs are written once. The sitemap covers all content;FeedDirectoryandFeedLocaledo not apply to it. - RSS. Each item has its title, link, a permalink
guid,pubDatefrom the creation date (date) and thedescriptionfront matter. The channel carries anatom:link rel="self"pointing to/feed.xml. - Atom. Each entry has an id (its URL), title, link,
published(the creation date),updated(the last-modified date, or the creation date), the author when set, and the description as its summary. The feed's ownupdatedis the newest entry's, or the current time for an empty feed. The feed-level author is the feed title, which satisfies Atom's rule that every entry has an author. - Feeds carry descriptions, not full article bodies. Unpublished items (
published: false) never appear, and a feed lists items by creation date even when a provider ignores the sort order. - Characters that XML cannot represent are dropped from titles and descriptions rather than failing the request.
Security and caching
Set SiteUrl, or Osirion:Seo:SiteUrl from the release after 4.1.0, in production. Without either, URLs follow whatever Host header a request sends, so a forged header could
put another host into a response that a cache or crawler stores. Responses are marked public, so browsers and
shared caches may keep serving a document for up to CacheDuration after the content changes.
Pointing crawlers and readers at them
Add the sitemap to your robots.txt:
Sitemap: https://example.com/sitemap.xml
Let browsers and feed readers discover the feeds from the page head, for example in App.razor:
<link rel="alternate" type="application/rss+xml" title="Example blog" href="/feed.xml" />
<link rel="alternate" type="application/atom+xml" title="Example blog" href="/atom.xml" />
Related
- SeoMetadataRenderer: head metadata; its
SiteNameandSiteDescriptionoptions also title the feeds - ContentList: the list pages whose links the feeds share
- CMS Web core components