antwar-rss-plugin
Advanced tools
Comparing version 0.3.1 to 0.8.1-alpha.5859eb8d
{ | ||
"name": "antwar-rss-plugin", | ||
"version": "0.3.1", | ||
"version": "0.8.1-alpha.5859eb8d", | ||
"description": "RSS plugin for antwar", | ||
@@ -12,3 +12,3 @@ "main": "src", | ||
"type": "git", | ||
"url": "https://github.com/antwarjs/rss-plugin.git" | ||
"url": "https://github.com/antwarjs/antwar.git" | ||
}, | ||
@@ -22,5 +22,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/antwarjs/rss-plugin/issues" | ||
"url": "https://github.com/antwarjs/antwar/issues" | ||
}, | ||
"homepage": "https://github.com/antwarjs/rss-plugin", | ||
"homepage": "https://github.com/antwarjs/antwar", | ||
"dependencies": { | ||
@@ -27,0 +27,0 @@ "absolutify": "0.0.2", |
@@ -1,30 +0,26 @@ | ||
'use strict'; | ||
var _url = require('url'); | ||
var _ = require('lodash'); | ||
var moment = require('moment'); | ||
var absolutify = require('absolutify') | ||
var urljoin = require('url-join'); | ||
const _url = require('url'); | ||
const _ = require('lodash'); | ||
const moment = require('moment'); | ||
const absolutify = require('absolutify'); | ||
const urljoin = require('url-join'); | ||
exports.feed = function (children) { | ||
return e('feed', {xmlns: 'http://www.w3.org/2005/Atom'}, children); | ||
} | ||
return e('feed', { xmlns: 'http://www.w3.org/2005/Atom' }, children); | ||
}; | ||
exports.title = function (title) { | ||
return e('title', {}, escapeHTML(title)); | ||
} | ||
}; | ||
exports.link = function (target, rel) { | ||
target = target || ''; | ||
rel = rel || ''; | ||
exports.link = function (target = '', rel = '') { | ||
return e('link', { href: target, rel }, ''); | ||
}; | ||
return e('link', {href: target, rel: rel}, ''); | ||
} | ||
exports.updated = function (date) { | ||
return e('updated', {}, date); | ||
} | ||
}; | ||
exports.id = function (value) { | ||
return e('id', {}, value); | ||
} | ||
}; | ||
@@ -34,10 +30,10 @@ exports.author = function (author) { | ||
e('name', {}, author ? escapeHTML(author.name || author) : ''), | ||
e('email', {}, author ? author.email || '' : ''), | ||
e('email', {}, author ? author.email || '' : '') | ||
]); | ||
} | ||
}; | ||
exports.entries = function (baseUrl, sections, pages) { | ||
return _.map(pages, function(page, name) { | ||
if(!_.includes(sections, page.section) || !page.title) { | ||
return; | ||
return _.map(pages, function (page, name) { | ||
if (!_.includes(sections, page.section) || !page.title) { | ||
return null; | ||
} | ||
@@ -50,27 +46,36 @@ | ||
{}, | ||
'a' + _.camelCase(_.escape(_.deburr(page.title))).toLowerCase() + | ||
'a' + _.camelCase(_.escape(_.deburr(page.title))).toLowerCase() + | ||
moment(page.date, 'YYYY-MM-DD').format().toLowerCase() | ||
), | ||
e('link', {href: _url.resolve(baseUrl, name)}, ''), | ||
e('updated', {}, moment(page.date, 'YYYY-MM-DD').format()), | ||
e('content', {type: 'html'}, escapeHTML(resolveUrls(baseUrl, page.section, page.content))), | ||
]); | ||
e('link', { href: _url.resolve(baseUrl, name) }, ''), | ||
e( | ||
'updated', | ||
{}, | ||
moment(page.date, 'YYYY-MM-DD').format() | ||
), | ||
e( | ||
'content', | ||
{ type: 'html' }, | ||
escapeHTML(resolveUrls(baseUrl, page.section, page.content)) | ||
) | ||
]); | ||
}).filter(_.identity).join(''); | ||
} | ||
}; | ||
function e(name, attributes, content) { | ||
var attrStr = _.map(attributes, function(val, key) { | ||
return key + '=' + '"' + val + '"'; | ||
let attrStr = _.map(attributes, function (val, key) { | ||
return key + '="' + val + '"'; | ||
}); | ||
let ret = content; | ||
attrStr = attrStr.length ? ' ' + attrStr.join(' ') : ''; | ||
if(_.isArray(content)) { | ||
content = content.join(''); | ||
if (_.isArray(content)) { | ||
ret = content.join(''); | ||
} | ||
return '<' + name + attrStr + '>' + content + '</' + name + '>'; | ||
}; | ||
return '<' + name + attrStr + '>' + ret + '</' + name + '>'; | ||
} | ||
function resolveUrls (baseUrl, section, content) { | ||
function resolveUrls(baseUrl, section, content) { | ||
return absolutify(content, function (url, attrName) { | ||
@@ -89,3 +94,7 @@ if (!url.indexOf('./')) { | ||
function escapeHTML (input) { | ||
function escapeHTML(input) { | ||
if (!input) { | ||
return ''; | ||
} | ||
return input.replace(/&/g, '&') | ||
@@ -92,0 +101,0 @@ .replace(/</g, '<') |
@@ -1,10 +0,7 @@ | ||
'use strict'; | ||
var url = require('url'); | ||
var e = require('./element'); | ||
const url = require('url'); | ||
const e = require('./element'); | ||
// TODO: simplify interface -> object format | ||
// TODO: Push to another package or use a pre-existing one over this | ||
module.exports = function (baseUrl, sections, updated, pages, config) { | ||
sections = sections || []; | ||
module.exports = function (baseUrl, sections = [], updated, pages, config) { | ||
return e.feed([ | ||
@@ -11,0 +8,0 @@ e.title(config.title), |
@@ -1,9 +0,8 @@ | ||
'use strict'; | ||
var generate = require('./generate'); | ||
var moment = require('moment'); | ||
const generate = require('./generate'); | ||
const moment = require('moment'); | ||
// Antwar wrapper | ||
module.exports = function(o) { | ||
module.exports = function (o) { | ||
return { | ||
extra: function(paths, config) { | ||
extra(paths, config) { | ||
return { | ||
@@ -10,0 +9,0 @@ 'atom.xml': generate( |
@@ -1,6 +0,5 @@ | ||
'use strict'; | ||
var test = require('tape'); | ||
var marked = require('marked'); | ||
var moment = require('moment'); | ||
var element = require('../src/element'); | ||
const test = require('tape'); | ||
const marked = require('marked'); | ||
const moment = require('moment'); | ||
const element = require('../src/element'); | ||
@@ -10,3 +9,3 @@ test('entries generate xml', function (t) { | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
@@ -26,5 +25,5 @@ const pages = { | ||
'<title>' + pages.demo.title + '</title>' + | ||
'<id>ademotitle2016-02-01t00:00:00+02:00</id>' + | ||
'<id>ademotitle' + moment(pages.demo.date, 'YYYY-MM-DD').format().toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html">' + pages.demo.content + '</content>' + | ||
@@ -39,3 +38,3 @@ '</entry>'; | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
@@ -57,3 +56,3 @@ const pages = { | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html"><p>#test\n<a href="http://google.com">check out</a></p>\n</content>' + | ||
@@ -68,3 +67,3 @@ '</entry>'; | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
@@ -84,5 +83,5 @@ const pages = { | ||
'<title>' + pages.demo.title + '</title>' + | ||
'<id>ademotitle2016-02-01t00:00:00+02:00</id>' + | ||
'<id>ademotitle' + moment(pages.demo.date, 'YYYY-MM-DD').format().toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
@@ -97,3 +96,3 @@ '</entry>'; | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
@@ -113,5 +112,5 @@ const pages = { | ||
'<title>' + pages.demo.title + '</title>' + | ||
'<id>ademotitle2016-02-01t00:00:00+02:00</id>' + | ||
'<id>ademotitle' + moment(pages.demo.date, 'YYYY-MM-DD').format().toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
@@ -126,3 +125,3 @@ '</entry>'; | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['blog']; | ||
@@ -142,5 +141,5 @@ const pages = { | ||
'<title>' + pages.demo.title + '</title>' + | ||
'<id>ademotitle2016-02-01t00:00:00+02:00</id>' + | ||
'<id>ademotitle' + moment(pages.demo.date, 'YYYY-MM-DD').format().toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
@@ -147,0 +146,0 @@ '</entry>'; |
@@ -1,5 +0,4 @@ | ||
'use strict'; | ||
var test = require('tape'); | ||
var moment = require('moment'); | ||
var generate = require('../src/generate'); | ||
const test = require('tape'); | ||
const moment = require('moment'); | ||
const generate = require('../src/generate'); | ||
@@ -9,3 +8,3 @@ test('generates dummy xml', function (t) { | ||
const baseUrl = 'http://demo.com/' | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
@@ -38,3 +37,3 @@ const pages = { | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<updated>' + moment(pages.demo.date, 'YYYY-MM-DD').format() + '</updated>' + | ||
'<content type="html">' + pages.demo.content + '</content>' + | ||
@@ -41,0 +40,0 @@ '</entry>' + |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
1
11197
8
270