How do you create an RSS feed using Jade?

I am creating my own front-end framework with Jade, and I was wondering if there is a way to create an RSS feed file that will be automatically updated with every compilation.

Is there a way to automatically create something like a JSON file with objects that contain page information that can be selected in a Jade loop?

+5
source share
1 answer

Yes, yes to everyone !!! You can do it. I will give an example to follow.

In js node

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") 

This is a great way to create content, you can display any kind of xml in jade.

+2
source

Source: https://habr.com/ru/post/1211914/


All Articles