Skip to content

Feed

Writes an Atom feed of the pages of a collection.

Add it

Terminal
dotnet add package Nacara.Plugin.Feed --prerelease
let posts =
    Collection.create "blog" PostFrontMatter.decoder
    |> Collection.title _.Title

let feed =
    Feed.ofCollection posts (fun post ->
        { Feed.entry post.Title post.Date with
            Summary = Some post.Excerpt
            Categories = [ post.Tag ]
        }
    )
    |> Feed.author "Ada Lovelace"

Site.create "My blog"
|> Site.origin "https://example.com"
|> Markdown.register
|> Feed.register feed
|> Site.collection (posts |> Collection.layout Layouts.post)

Feed.ofCollection takes the collection and a function from a page's front matter to its entry.

Site.origin is required. Without it, no feed is written and the build reports feed/origin-missing.

The feed lists the pages of the root locale, newest first. It is written once the pages are rendered, so the link validator sees it.

Feed.headLink renders the <link rel="alternate"> for a page's head:

Html.head
    [
        yield! Head.meta model
        Feed.headLink context.Site feed
    ]

Entries

Feed.entry title published creates an entry with a title and a publication date.

FieldDefaultEffect
TitleThe entry's title
PublishedWhen the page was published
UpdatedNoneWhen the page last changed. Published is used when it is None
SummaryNoneA short description of the page
Categories[]The categories the entry is filed under

Options

OptionDefaultEffect
Path"feed.xml"Where the feed is written, relative to the output
TitleNoneThe feed's title. The site's title is used when it is None
Authors[]The feed's authors
LimitSome 20How many entries the feed holds. None holds every page
IncludeContenttruePut each page's rendered body in its entry

Feed.path, Feed.title, Feed.author, Feed.limit and Feed.includeContent set them:

Feed.ofCollection posts describe
|> Feed.title "Release notes"
|> Feed.author "Ada Lovelace"
|> Feed.limit None

Several feeds

Register the plugin once per feed, each with its own Path:

|> Feed.register (Feed.ofCollection posts describe)
|> Feed.register (Feed.ofCollection notes describe |> Feed.path "notes.xml")

Reference

Every function and option of it, signature by signature: Feed.

Edit this page