Last active
December 11, 2016 01:17
-
-
Save trescenzi/88df9da1a1ce1d7eecc9a0ab845ef11f to your computer and use it in GitHub Desktop.
Vue 2 rendering an RSS Feed
This file contains hidden or 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
const Vue = require('vue'); | |
const renderer = require('vue-server-renderer').createRenderer(); | |
const rssData = { | |
title: 'Test Feed', | |
link: 'www.test.com', | |
desc: 'A test rss feed', | |
items: [ | |
{ | |
title: 'Test number 1', | |
link: 'www.test.com/1', | |
desc: 'The first test', | |
author: 'Test Bro', | |
}, | |
{ | |
title: 'Test number 2', | |
link: 'www.test.com/2', | |
desc: 'The second test', | |
author: 'Fred', | |
}, | |
{ | |
title: 'Test number 3', | |
link: 'www.test.com/3', | |
desc: 'The last test', | |
author: 'Anne', | |
}, | |
], | |
}; | |
const rss = new Vue({ | |
template: ` | |
<channel> | |
<title>{{title}}</title> | |
<link>{{link}}</link> | |
<description>{{desc}}</descripton> | |
<item v-for="item in items"> | |
<title>{{item.title}}</title> | |
<link>{{item.link}}</link> | |
<description>{{item.desc}}</description> | |
<author>{{item.author}}</author> | |
</item> | |
</channel> | |
</rss> | |
`, | |
data: rssData | |
}); | |
let xml = ` | |
<?xml version="1.0" encoding="UTF-8" ?> | |
<rss version="2.0"> | |
`; | |
renderer.renderToString(rss, (err, output) => { | |
xml += output; | |
console.log(xml); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment