RSS function

This commit is contained in:
Clément GOUIN
2019-06-20 15:08:22 +02:00
parent 7937985c3d
commit 1fa8007e0e
5 changed files with 152 additions and 7 deletions
+3
View File
@@ -2,6 +2,7 @@
"node_port": 3000,
"data_dir": "data",
"view_engine": "ejs",
"loopback_url": "http://localhost:3000",
"modules": {
"plantuml": false,
"rss": true,
@@ -22,6 +23,8 @@
"default_thumbnail": null
},
"rss": {
"title": "mygitblog RSS feed",
"description": "a generated RSS feed from my articles",
"endpoint": "/rss",
"length": 10
},
+40
View File
@@ -0,0 +1,40 @@
const convert = require('xml-js');
const mapArticle = (url, article) => {
return {
'title': {'_text': article.title},
'link': {'_text': (url + article.url).replace(/([^:])\/\//g, '$1/')},
'pubDate': {'_text': article.date.toString()},
};
};
module.exports = (config) => {
return {
get: (dict) => {
const items = Object.values(dict)
.sort((a, b) => ('' + b.path).localeCompare(a.path))
.slice(0, config['rss']['length']);
const data = {
'_declaration': {
'_attributes': {
'version': '1.0',
'encoding': 'UTF-8'
}
},
'rss': {
'_attributes': {
'version': '2.0'
},
'title': {'_text': config['rss']['title']},
'description': {'_text': config['rss']['description']},
'link': {'_text': config['loopback_url']},
'lastBuildDate': {'_text': new Date().toString()},
'lastPubDate': {'_text': new Date().toString()},
'ttl': {'_text': '60'},
'item': items.map((a) => mapArticle(config['loopback_url'], a))
}
};
return convert.js2xml(data, {compact: true});
}
};
};