Created
February 6, 2011 02:28
-
-
Save bmavity/813043 to your computer and use it in GitHub Desktop.
Generating an atom feed with a JavaScript DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var generateUniqueId = function(post) { | |
return [ | |
'tag:brianmavity.com,', | |
post.publishDate.slice(0, 10), | |
':/blog/', | |
post.publishDate.replace(/T|Z|\.|:|-/g, '') | |
]; | |
}; | |
doc( | |
'<?xml version="1.0" encoding="utf-8"?>', | |
feed({ xmlns: 'http://www.w3.org/2005/Atom' }, | |
link({ rel: 'self', href: 'http://blog.brianmavity.com/blog/atom' }), | |
id('tag:brianmavity.com,2008:/blog'), | |
title('brianmavity.com'), | |
subtitle('Learn with me'), | |
link({ href: 'http://blog.brianmavity.com/' }), | |
updated(posts[0].publishDate), | |
author( | |
name('Brian Mavity') | |
), | |
posts.map(function(post) { | |
return entry( | |
title(post.title), | |
link({ href: 'http://blog.brianmavity.com/' + post.slug }), | |
id(generateUniqueId(post)), | |
published(post.publishDate), | |
updated(post.publishDate), | |
content({ type: 'html' }, htmlEncode(post.content)), | |
author( | |
name(post.author) | |
) | |
) | |
}) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment