Custom Atom Feed

37 views
Skip to first unread message

Nick Charlton

unread,
Nov 10, 2012, 11:00:06 AM11/10/12
to hak...@googlegroups.com
Hi,

I'm in the process of assembling an atom feed from my post list (I'm using a custom chronological sort, because I don't have dates in the filenames.) But, I'm stuck on how to get the following:

1. Full URLs.

Using the $url$ placeholder, I can get the relative URI for a post. How would I either combine the root URI or find out the full one inside a post?

2. Updated date if present

In my post metadata, I'm typically only defining "published:". But, occasionally I'll define it. How could I set the published date to copy over to the updated date if the "updated" metadata is not present?

3. Last updated post date

This is for the main <feed><updated> field. What's the easiest way of getting that?

I have a list of posts, the top item will be the most recent, see:

myChronological :: [Page a] -> [Page a]
myChronological = reverse . (sortBy $ comparing $ getField "published")

And so:

-- Render RSS feed
match "atom.xml" $ route idRoute 
create "atom.xml" $ constA mempty
    >>> setFieldPageList myChronological
            "templates/atom_item.xml" "posts" "posts/*"
    >>> arr (copyBodyToField "description")
    >>> arr applySelf
    >>> applyTemplateCompiler "templates/atom.xml"
    >>> relativizeUrlsCompiler

Thanks,

Nick.

Jasper Van der Jeugt

unread,
Nov 10, 2012, 12:34:38 PM11/10/12
to hak...@googlegroups.com
Hello,

There already is code for generating Atom feeds: `renderAtom` from the
`Hakyll.Web.Feed` module. If this is not satisfactory, look at the
source code for `Hakyll.Web.Feed` [1], which should help you out where
you're stuck.

[1]: https://github.com/jaspervdj/hakyll/blob/master/src/Hakyll/Web/Feed.hs

Peace,
Jasper

Nick Charlton

unread,
Nov 10, 2012, 12:38:41 PM11/10/12
to hak...@googlegroups.com
Hi Jasper,

Yeah, I figured that because I wasn't doing my filenames/urls as Hakyll expected then that was why I wasn't getting articles showing up in the Atom feed correctly.

A quick glance suggests that'll solve it all.

Thanks,

Nick.
Reply all
Reply to author
Forward
0 new messages