Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #56 from ft-interactive/rss-feed
Browse files Browse the repository at this point in the history
Create RSS file in production build
  • Loading branch information
Sumeet Adur committed Dec 22, 2015
2 parents 1d1f445 + 4b99a0e commit 7f8b30f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/client/words.json
/client/homewords.json
npm-debug.log
rss.xml
29 changes: 28 additions & 1 deletion gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ gulp.task('build', done => {

runSequence(
// preparatory
['clean', /* 'scsslint', 'eslint', */ 'download-data'],
['clean', /* 'scsslint', 'eslint', */ 'download-data', 'create-rss-feed'],
// preprocessing (client/templates => .tmp)
['scripts', 'styles', 'templates'],
// optimisation (+ copying over misc files) (.tmp/client => dist)
Expand Down Expand Up @@ -382,3 +382,30 @@ gulp.task('templates', () => {
})
fs.writeFileSync(`.tmp/thanks.html`, thanksPageHtml);
});

gulp.task('create-rss-feed', ['download-data'], () => {

const rssTitle = 'Guffipedia';
const rssLink = 'http://ft.com/guff';
const rssDescription = 'Lucy Kellaway’s dictionary of business jargon and corporate nonsense';

const words = JSON.parse(fs.readFileSync('client/words.json', 'utf8'));

let wordArray = Object.keys(words);
let dateIndex = wordArray.sort(function (a, b) {
return new Date(words[b].submissiondate) - new Date(words[a].submissiondate);
});

let rssString = `<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>${rssTitle}</title><link>${rssLink}</link><description>${rssDescription}</description>`;
for (const word of dateIndex) {
rssString += '<item>';
rssString += `<title>${words[word].word}</title>`;
rssString += `<link>http://ig.ft.com/sites/guffipedia/${words[word].slug}/</link>`;
rssString += `<guid>http://ig.ft.com/sites/guffipedia/${words[word].slug}/</guid>`;
rssString += `<description>${words[word].definition}</description>`;
rssString += '</item>';
}
rssString += '</channel></rss>';

fs.writeFileSync('rss.xml', rssString);
});

0 comments on commit 7f8b30f

Please sign in to comment.