antwar-rss-plugin
Advanced tools
Comparing version 0.18.0 to 0.19.0
@@ -1,33 +0,33 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _url = require('url'); | ||
var _ = require('lodash'); | ||
var absolutify = require('absolutify'); | ||
var urljoin = require('url-join'); | ||
var _url = require("url"); | ||
var _ = require("lodash"); | ||
var absolutify = require("absolutify"); | ||
var 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)); | ||
return e("title", {}, escapeHTML(title)); | ||
}; | ||
exports.link = function () { | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var rel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; | ||
var rel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; | ||
return e('link', { href: target, rel: rel }, ''); | ||
return e("link", { href: target, rel: rel }, ""); | ||
}; | ||
exports.updated = function (date) { | ||
return e('updated', {}, date); | ||
return e("updated", {}, date); | ||
}; | ||
exports.id = function (value) { | ||
return e('id', {}, value); | ||
return e("id", {}, value); | ||
}; | ||
exports.author = function (author) { | ||
return e('author', {}, [e('name', {}, author ? escapeHTML(author.name || author) : ''), e('email', {}, author ? author.email || '' : '')]); | ||
return e("author", {}, [e("name", {}, author ? escapeHTML(author.name || author) : ""), e("email", {}, author ? author.email || "" : "")]); | ||
}; | ||
@@ -44,3 +44,3 @@ | ||
if (!_.includes(sections, sectionName) || page.type !== 'page') { | ||
if (!_.includes(sections, sectionName) || page.type !== "page") { | ||
return null; | ||
@@ -53,4 +53,4 @@ } | ||
return e('entry', {}, [e('title', {}, escapeHTML(pageTitle)), e('id', {}, 'a' + _.camelCase(_.escape(_.deburr(pageTitle))).toLowerCase() + pageDate.toLowerCase()), e('link', { href: _url.resolve(baseUrl, name) }, ''), e('updated', {}, pageDate), e('content', { type: 'html' }, escapeHTML(resolveUrls(baseUrl, sectionName, pageContent)))]); | ||
}).filter(_.identity).join(''); | ||
return e("entry", {}, [e("title", {}, escapeHTML(pageTitle)), e("id", {}, "a" + _.camelCase(_.escape(_.deburr(pageTitle))).toLowerCase() + pageDate.toLowerCase()), e("link", { href: _url.resolve(baseUrl, name) }, ""), e("updated", {}, pageDate), e("content", { type: "html" }, escapeHTML(resolveUrls(baseUrl, sectionName, pageContent)))]); | ||
}).filter(_.identity).join(""); | ||
}; | ||
@@ -64,9 +64,9 @@ | ||
attrStr = attrStr.length ? ' ' + attrStr.join(' ') : ''; | ||
attrStr = attrStr.length ? " " + attrStr.join(" ") : ""; | ||
if (_.isArray(content)) { | ||
ret = content.join(''); | ||
ret = content.join(""); | ||
} | ||
return '<' + name + attrStr + '>' + ret + '</' + name + '>'; | ||
return "<" + name + attrStr + ">" + ret + "</" + name + ">"; | ||
} | ||
@@ -76,8 +76,8 @@ | ||
return absolutify(content, function (url, attrName) { | ||
if (!url.indexOf('./')) { | ||
return urljoin(baseUrl, section, _.trimStart(url, './')); | ||
if (!url.indexOf("./")) { | ||
return urljoin(baseUrl, section, _.trimStart(url, "./")); | ||
} | ||
if (attrName === 'href') { | ||
return _.trimEnd(_url.resolve(baseUrl, url), '/'); | ||
if (attrName === "href") { | ||
return _.trimEnd(_url.resolve(baseUrl, url), "/"); | ||
} | ||
@@ -91,6 +91,6 @@ | ||
if (!input) { | ||
return ''; | ||
return ""; | ||
} | ||
return input.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); | ||
return input.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"); | ||
} |
@@ -1,6 +0,6 @@ | ||
'use strict'; | ||
"use strict"; | ||
var marked = require('marked'); | ||
var moment = require('moment'); | ||
var element = require('./element'); | ||
var marked = require("marked"); | ||
var moment = require("moment"); | ||
var element = require("./element"); | ||
@@ -19,13 +19,13 @@ var get = { | ||
describe('Element', function () { | ||
it('entries generate xml', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['demoSection']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = 'demo'; | ||
describe("Element", function () { | ||
it("entries generate xml", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["demoSection"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = "demo"; | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -48,3 +48,3 @@ attributes: { | ||
var expected = '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html">' + body + '</content>' + '</entry>'; | ||
var expected = "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html">' + body + "</content>" + "</entry>"; | ||
@@ -54,12 +54,12 @@ expect(result).toEqual(expected); | ||
it('do not resolve full urls', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['demoSection']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = marked('#test\n[check out](http://google.com)'); | ||
it("do not resolve full urls", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["demoSection"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = marked("#test\n[check out](http://google.com)"); | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -82,3 +82,3 @@ attributes: { | ||
var expected = '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html"><p>#test\n<a href="http://google.com">check out</a></p>\n</content>' + '</entry>'; | ||
var expected = "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html"><p>#test\n<a href="http://google.com">check out</a></p>\n</content>' + "</entry>"; | ||
@@ -88,12 +88,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve relative urls against base', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['demoSection']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = marked('#test\n[check out](../blog/demo-interview)'); | ||
it("entries resolve relative urls against base", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["demoSection"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = marked("#test\n[check out](../blog/demo-interview)"); | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -116,3 +116,3 @@ attributes: { | ||
var expected = '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + '</entry>'; | ||
var expected = "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + "</entry>"; | ||
@@ -122,12 +122,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve absolute urls against base', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['demoSection']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = marked('#test\n[check out](/blog/demo-interview)'); | ||
it("entries resolve absolute urls against base", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["demoSection"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = marked("#test\n[check out](/blog/demo-interview)"); | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -150,3 +150,3 @@ attributes: { | ||
var expected = '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + '</entry>'; | ||
var expected = "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + "</entry>"; | ||
@@ -156,12 +156,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve relative urls against base', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['blog']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = marked('#test\n[check out](./demo-interview)'); | ||
it("entries resolve relative urls against base", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["blog"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = marked("#test\n[check out](./demo-interview)"); | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'blog', | ||
type: "page", | ||
sectionName: "blog", | ||
file: { | ||
@@ -184,3 +184,3 @@ attributes: { | ||
var expected = '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + '</entry>'; | ||
var expected = "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + "</entry>"; | ||
@@ -187,0 +187,0 @@ expect(result).toEqual(expected); |
@@ -1,5 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var url = require('url'); | ||
var e = require('./element'); | ||
var url = require("url"); | ||
var e = require("./element"); | ||
@@ -16,3 +16,3 @@ // TODO: Push to another package or use a pre-existing one over this | ||
return e.feed([e.title(config.title), e.link(url.resolve(baseUrl, '/atom.xml'), 'self'), e.link(baseUrl), e.updated(updated), e.id(baseUrl), e.author(config.author), e.entries({ baseUrl: baseUrl, sections: sections, pages: pages, get: get })]); | ||
return e.feed([e.title(config.title), e.link(url.resolve(baseUrl, "/atom.xml"), "self"), e.link(baseUrl), e.updated(updated), e.id(baseUrl), e.author(config.author), e.entries({ baseUrl: baseUrl, sections: sections, pages: pages, get: get })]); | ||
}; |
@@ -1,17 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
var moment = require('moment'); | ||
var generate = require('./generate'); | ||
var moment = require("moment"); | ||
var generate = require("./generate"); | ||
describe('Generate', function () { | ||
it('generates dummy xml', function () { | ||
var baseUrl = 'http://demo.com/'; | ||
var sections = ['demoSection']; | ||
var title = 'demo title'; | ||
var date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
var body = 'demo'; | ||
describe("Generate", function () { | ||
it("generates dummy xml", function () { | ||
var baseUrl = "http://demo.com/"; | ||
var sections = ["demoSection"]; | ||
var title = "demo title"; | ||
var date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
var body = "demo"; | ||
var pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -27,4 +27,4 @@ attributes: { | ||
var config = { | ||
title: 'Demo RSS', | ||
author: 'Demo Author' | ||
title: "Demo RSS", | ||
author: "Demo Author" | ||
}; | ||
@@ -51,3 +51,3 @@ var updated = moment().format(); | ||
}); | ||
var expected = '<feed xmlns="http://www.w3.org/2005/Atom">' + '<title>' + config.title + '</title>' + '<link href="' + baseUrl + 'atom.xml" rel="self"></link>' + '<link href="' + baseUrl + '" rel=""></link>' + '<updated>' + updated + '</updated>' + '<id>' + baseUrl + '</id>' + '<author><name>' + config.author + '</name><email></email></author>' + '<entry>' + '<title>' + title + '</title>' + '<id>ademotitle' + date.toLowerCase() + '</id>' + '<link href="' + baseUrl + 'demo"></link>' + '<updated>' + date + '</updated>' + '<content type="html">' + body + '</content>' + '</entry>' + '</feed>'; | ||
var expected = '<feed xmlns="http://www.w3.org/2005/Atom">' + "<title>" + config.title + "</title>" + '<link href="' + baseUrl + 'atom.xml" rel="self"></link>' + '<link href="' + baseUrl + '" rel=""></link>' + "<updated>" + updated + "</updated>" + "<id>" + baseUrl + "</id>" + "<author><name>" + config.author + "</name><email></email></author>" + "<entry>" + "<title>" + title + "</title>" + "<id>ademotitle" + date.toLowerCase() + "</id>" + '<link href="' + baseUrl + 'demo"></link>' + "<updated>" + date + "</updated>" + '<content type="html">' + body + "</content>" + "</entry>" + "</feed>"; | ||
@@ -54,0 +54,0 @@ expect(result).toEqual(expected); |
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
var generate = require('./generate'); | ||
var generate = require("./generate"); | ||
@@ -14,3 +14,3 @@ // Antwar wrapper | ||
return { | ||
'atom.xml': generate({ | ||
"atom.xml": generate({ | ||
baseUrl: baseUrl, | ||
@@ -17,0 +17,0 @@ sections: sections, |
{ | ||
"name": "antwar-rss-plugin", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "RSS plugin for antwar", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
@@ -1,43 +0,38 @@ | ||
const _url = require('url'); | ||
const _ = require('lodash'); | ||
const absolutify = require('absolutify'); | ||
const urljoin = require('url-join'); | ||
const _url = require("url"); | ||
const _ = require("lodash"); | ||
const absolutify = require("absolutify"); | ||
const urljoin = require("url-join"); | ||
exports.feed = function (children) { | ||
return e('feed', { xmlns: 'http://www.w3.org/2005/Atom' }, children); | ||
exports.feed = function(children) { | ||
return e("feed", { xmlns: "http://www.w3.org/2005/Atom" }, children); | ||
}; | ||
exports.title = function (title) { | ||
return e('title', {}, escapeHTML(title)); | ||
exports.title = function(title) { | ||
return e("title", {}, escapeHTML(title)); | ||
}; | ||
exports.link = function (target = '', rel = '') { | ||
return e('link', { href: target, rel }, ''); | ||
exports.link = function(target = "", rel = "") { | ||
return e("link", { href: target, rel }, ""); | ||
}; | ||
exports.updated = function (date) { | ||
return e('updated', {}, date); | ||
exports.updated = function(date) { | ||
return e("updated", {}, date); | ||
}; | ||
exports.id = function (value) { | ||
return e('id', {}, value); | ||
exports.id = function(value) { | ||
return e("id", {}, value); | ||
}; | ||
exports.author = function (author) { | ||
return e('author', {}, [ | ||
e('name', {}, author ? escapeHTML(author.name || author) : ''), | ||
e('email', {}, author ? author.email || '' : '') | ||
exports.author = function(author) { | ||
return e("author", {}, [ | ||
e("name", {}, author ? escapeHTML(author.name || author) : ""), | ||
e("email", {}, author ? author.email || "" : "") | ||
]); | ||
}; | ||
exports.entries = function ({ | ||
baseUrl, | ||
sections, | ||
pages, | ||
get | ||
}) { | ||
return _.map(pages, function (page, name) { | ||
exports.entries = function({ baseUrl, sections, pages, get }) { | ||
return _.map(pages, function(page, name) { | ||
const sectionName = page.sectionName; | ||
if (!_.includes(sections, sectionName) || page.type !== 'page') { | ||
if (!_.includes(sections, sectionName) || page.type !== "page") { | ||
return null; | ||
@@ -50,26 +45,26 @@ } | ||
return e('entry', {}, [ | ||
e('title', {}, escapeHTML(pageTitle)), | ||
return e("entry", {}, [ | ||
e("title", {}, escapeHTML(pageTitle)), | ||
e( | ||
'id', | ||
"id", | ||
{}, | ||
'a' + _.camelCase(_.escape(_.deburr(pageTitle))).toLowerCase() + pageDate.toLowerCase() | ||
"a" + | ||
_.camelCase(_.escape(_.deburr(pageTitle))).toLowerCase() + | ||
pageDate.toLowerCase() | ||
), | ||
e('link', { href: _url.resolve(baseUrl, name) }, ''), | ||
e("link", { href: _url.resolve(baseUrl, name) }, ""), | ||
e("updated", {}, pageDate), | ||
e( | ||
'updated', | ||
{}, | ||
pageDate | ||
), | ||
e( | ||
'content', | ||
{ type: 'html' }, | ||
"content", | ||
{ type: "html" }, | ||
escapeHTML(resolveUrls(baseUrl, sectionName, pageContent)) | ||
) | ||
]); | ||
}).filter(_.identity).join(''); | ||
}) | ||
.filter(_.identity) | ||
.join(""); | ||
}; | ||
function e(name, attributes, content) { | ||
let attrStr = _.map(attributes, function (val, key) { | ||
let attrStr = _.map(attributes, function(val, key) { | ||
return key + '="' + val + '"'; | ||
@@ -79,19 +74,19 @@ }); | ||
attrStr = attrStr.length ? ' ' + attrStr.join(' ') : ''; | ||
attrStr = attrStr.length ? " " + attrStr.join(" ") : ""; | ||
if (_.isArray(content)) { | ||
ret = content.join(''); | ||
ret = content.join(""); | ||
} | ||
return '<' + name + attrStr + '>' + ret + '</' + name + '>'; | ||
return "<" + name + attrStr + ">" + ret + "</" + name + ">"; | ||
} | ||
function resolveUrls(baseUrl, section, content) { | ||
return absolutify(content, function (url, attrName) { | ||
if (!url.indexOf('./')) { | ||
return urljoin(baseUrl, section, _.trimStart(url, './')); | ||
return absolutify(content, function(url, attrName) { | ||
if (!url.indexOf("./")) { | ||
return urljoin(baseUrl, section, _.trimStart(url, "./")); | ||
} | ||
if (attrName === 'href') { | ||
return _.trimEnd(_url.resolve(baseUrl, url), '/'); | ||
if (attrName === "href") { | ||
return _.trimEnd(_url.resolve(baseUrl, url), "/"); | ||
} | ||
@@ -105,10 +100,11 @@ | ||
if (!input) { | ||
return ''; | ||
return ""; | ||
} | ||
return input.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
return input | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, """) | ||
.replace(/'/g, "'"); | ||
} |
@@ -1,4 +0,4 @@ | ||
const marked = require('marked'); | ||
const moment = require('moment'); | ||
const element = require('./element'); | ||
const marked = require("marked"); | ||
const moment = require("moment"); | ||
const element = require("./element"); | ||
@@ -11,13 +11,13 @@ const get = { | ||
describe('Element', () => { | ||
it('entries generate xml', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = 'demo'; | ||
describe("Element", () => { | ||
it("entries generate xml", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["demoSection"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = "demo"; | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -40,9 +40,20 @@ attributes: { | ||
const expected = '<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
'<content type="html">' + body + '</content>' + | ||
'</entry>'; | ||
const expected = | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html">' + | ||
body + | ||
"</content>" + | ||
"</entry>"; | ||
@@ -52,12 +63,12 @@ expect(result).toEqual(expected); | ||
it('do not resolve full urls', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = marked('#test\n[check out](http://google.com)'); | ||
it("do not resolve full urls", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["demoSection"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = marked("#test\n[check out](http://google.com)"); | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -80,9 +91,18 @@ attributes: { | ||
const expected = '<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
const expected = | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html"><p>#test\n<a href="http://google.com">check out</a></p>\n</content>' + | ||
'</entry>'; | ||
"</entry>"; | ||
@@ -92,12 +112,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve relative urls against base', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = marked('#test\n[check out](../blog/demo-interview)'); | ||
it("entries resolve relative urls against base", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["demoSection"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = marked("#test\n[check out](../blog/demo-interview)"); | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -120,9 +140,18 @@ attributes: { | ||
const expected = '<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
const expected = | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
'</entry>'; | ||
"</entry>"; | ||
@@ -132,12 +161,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve absolute urls against base', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = marked('#test\n[check out](/blog/demo-interview)'); | ||
it("entries resolve absolute urls against base", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["demoSection"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = marked("#test\n[check out](/blog/demo-interview)"); | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -160,9 +189,18 @@ attributes: { | ||
const expected = '<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
const expected = | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
'</entry>'; | ||
"</entry>"; | ||
@@ -172,12 +210,12 @@ expect(result).toEqual(expected); | ||
it('entries resolve relative urls against base', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['blog']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = marked('#test\n[check out](./demo-interview)'); | ||
it("entries resolve relative urls against base", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["blog"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = marked("#test\n[check out](./demo-interview)"); | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'blog', | ||
type: "page", | ||
sectionName: "blog", | ||
file: { | ||
@@ -200,9 +238,18 @@ attributes: { | ||
const expected = '<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
const expected = | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html"><p>#test\n<a href="http://demo.com/blog/demo-interview">check out</a></p>\n</content>' + | ||
'</entry>'; | ||
"</entry>"; | ||
@@ -209,0 +256,0 @@ expect(result).toEqual(expected); |
@@ -1,6 +0,6 @@ | ||
const url = require('url'); | ||
const e = require('./element'); | ||
const url = require("url"); | ||
const e = require("./element"); | ||
// TODO: Push to another package or use a pre-existing one over this | ||
module.exports = function ({ | ||
module.exports = function({ | ||
baseUrl, | ||
@@ -15,3 +15,3 @@ sections = [], | ||
e.title(config.title), | ||
e.link(url.resolve(baseUrl, '/atom.xml'), 'self'), | ||
e.link(url.resolve(baseUrl, "/atom.xml"), "self"), | ||
e.link(baseUrl), | ||
@@ -18,0 +18,0 @@ e.updated(updated), |
@@ -1,15 +0,15 @@ | ||
const moment = require('moment'); | ||
const generate = require('./generate'); | ||
const moment = require("moment"); | ||
const generate = require("./generate"); | ||
describe('Generate', () => { | ||
it('generates dummy xml', () => { | ||
const baseUrl = 'http://demo.com/'; | ||
const sections = ['demoSection']; | ||
const title = 'demo title'; | ||
const date = moment('2016-02-21', 'YYYY-MM-DD').utcOffset(0).format(); | ||
const body = 'demo'; | ||
describe("Generate", () => { | ||
it("generates dummy xml", () => { | ||
const baseUrl = "http://demo.com/"; | ||
const sections = ["demoSection"]; | ||
const title = "demo title"; | ||
const date = moment("2016-02-21", "YYYY-MM-DD").utcOffset(0).format(); | ||
const body = "demo"; | ||
const pages = { | ||
demo: { | ||
type: 'page', | ||
sectionName: 'demoSection', | ||
type: "page", | ||
sectionName: "demoSection", | ||
file: { | ||
@@ -25,4 +25,4 @@ attributes: { | ||
const config = { | ||
title: 'Demo RSS', | ||
author: 'Demo Author' | ||
title: "Demo RSS", | ||
author: "Demo Author" | ||
}; | ||
@@ -43,17 +43,40 @@ const updated = moment().format(); | ||
}); | ||
const expected = '<feed xmlns="http://www.w3.org/2005/Atom">' + | ||
'<title>' + config.title + '</title>' + | ||
'<link href="' + baseUrl + 'atom.xml" rel="self"></link>' + | ||
'<link href="' + baseUrl + '" rel=""></link>' + | ||
'<updated>' + updated + '</updated>' + | ||
'<id>' + baseUrl + '</id>' + | ||
'<author><name>' + config.author + '</name><email></email></author>' + | ||
'<entry>' + | ||
'<title>' + title + '</title>' + | ||
'<id>ademotitle' + date.toLowerCase() + '</id>' + | ||
'<link href="' + baseUrl + 'demo"></link>' + | ||
'<updated>' + date + '</updated>' + | ||
'<content type="html">' + body + '</content>' + | ||
'</entry>' + | ||
'</feed>'; | ||
const expected = | ||
'<feed xmlns="http://www.w3.org/2005/Atom">' + | ||
"<title>" + | ||
config.title + | ||
"</title>" + | ||
'<link href="' + | ||
baseUrl + | ||
'atom.xml" rel="self"></link>' + | ||
'<link href="' + | ||
baseUrl + | ||
'" rel=""></link>' + | ||
"<updated>" + | ||
updated + | ||
"</updated>" + | ||
"<id>" + | ||
baseUrl + | ||
"</id>" + | ||
"<author><name>" + | ||
config.author + | ||
"</name><email></email></author>" + | ||
"<entry>" + | ||
"<title>" + | ||
title + | ||
"</title>" + | ||
"<id>ademotitle" + | ||
date.toLowerCase() + | ||
"</id>" + | ||
'<link href="' + | ||
baseUrl + | ||
'demo"></link>' + | ||
"<updated>" + | ||
date + | ||
"</updated>" + | ||
'<content type="html">' + | ||
body + | ||
"</content>" + | ||
"</entry>" + | ||
"</feed>"; | ||
@@ -60,0 +83,0 @@ expect(result).toEqual(expected); |
@@ -1,13 +0,9 @@ | ||
const generate = require('./generate'); | ||
const generate = require("./generate"); | ||
// Antwar wrapper | ||
module.exports = function ({ | ||
baseUrl, | ||
sections, | ||
get | ||
}) { | ||
module.exports = function({ baseUrl, sections, get }) { | ||
return { | ||
extra(pages, config) { | ||
return { | ||
'atom.xml': generate({ | ||
"atom.xml": generate({ | ||
baseUrl, | ||
@@ -14,0 +10,0 @@ sections, |
24165
748