I'm building my own front-end framework with Jade, and I was wondering if there is a way to build an RSS feed file that will get updated automatically on every compile.
Is there a way to automatically create something like a JSON file with objects that contain page information that can be fetched in a Jade loop?
Yes, Yes to all !!! you can do that. I will give an example to follow.
In the nodejs
app.all('/myCool.:name(rss|xml)', function(req, res){
res.type('xml'); // <-- Type of the file
// myFeeds is a Array!!
res.render(req.params.name, { myFeeds : myFeeds, url : req.originalUrl });
});
In RSS rss
doctype xml
rss( version="2.0", xmlns:content="http://purl.org/rss/1.0/modules/content/", xmlns:atom='http://www.w3.org/2005/Atom' )
channel
title My Cool feed
link= url
//- I use momentjs
lastBuildDate= moment().toUTCString()
docs http://blogs.law.harvard.edu/tech/rs
generator My Nodejs Generator Feeds for RSS
each feed, i in myFeeds
item
title= feed.title
guid( isPermaLink="true" )= feed.id
updated= feed.date.toUTCString()
In Atom xml
doctype xml
feed( xmlns='http://www.w3.org/2005/Atom', xml:lang='es')
link( href= url, rel='self' )
//- I use momentjs
updated= moment().format("YYYY-MM-DDTHH:mm:ssZ")
title My Cool feed
author
name AlejoNext
uri https://alejonext.co
generator My Nodejs Generator Feeds for Atom
each feed, i in myFeeds
entry
title!= feed.title
id= feed.id
updated= moment(feed.date).format("YYYY-MM-DDTHH:mm:ssZ")
It is an excellent way to generate content, you can render any kind of xml
in jade.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With