tumblr-2-pe-epub
Advanced tools
Comparing version 0.2.0 to 0.3.0
106
index.js
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Tumblr2Peepub, tumblr; | ||
var Tumblr2Peepub, cheerio, tumblr; | ||
tumblr = require('tumblr'); | ||
cheerio = require('cheerio'); | ||
Tumblr2Peepub = function(tumblrConfig) { | ||
var allPosts, bookDoc, fetchPosts, that, totalPosts; | ||
var allPosts, bookDoc, fetchPosts, formatPosts, that, totalPosts; | ||
that = this; | ||
@@ -24,3 +26,3 @@ this.tumblrConfig = tumblrConfig; | ||
bookDoc = { | ||
title: res.blog.title, | ||
title: res.blog.title || that.blogUrl, | ||
url: 'http://' + that.blogUrl, | ||
@@ -39,2 +41,85 @@ subtitle: res.blog.description, | ||
}; | ||
formatPosts = function(p) { | ||
var $, body, embed_code, exp, pbody, pcap, pdesc, pphotos, pquotesrc, psource, ptext, ptitle, pvideo, regex, title, video_domain, video_url; | ||
if (p.title) { | ||
ptitle = "<h1>" + p.title + "</h1>"; | ||
} else { | ||
ptitle = ""; | ||
} | ||
if (p.source_url) { | ||
psource = "<p>Source: <a href=\"" + p.source_url + "\">" + p.source_title + "</a></p>"; | ||
} else { | ||
psource = ""; | ||
} | ||
if (p.body) { | ||
pbody = p.body; | ||
} else { | ||
pbody = ""; | ||
} | ||
if (p.text) { | ||
ptext = "<h1><blockquote>“" + p.text + "”</blockquote></h1>"; | ||
} else { | ||
ptext = ""; | ||
} | ||
if (p.source) { | ||
pquotesrc = "<p>— " + p.source + "</p>"; | ||
} else { | ||
pquotesrc = ""; | ||
} | ||
if (p.url) { | ||
if (p.title) { | ||
ptitle = "<h1><a href=\"" + p.url + "\">" + p.title + "</a></h1>"; | ||
} else { | ||
ptitle = "<h1><a href=\"" + p.url + "\">" + p.url + "</a></h1>"; | ||
} | ||
} | ||
if (p.description) { | ||
pdesc = p.description; | ||
} else { | ||
pdesc = ""; | ||
} | ||
if (p.player) { | ||
if (p.player[0]["embed_code"]) { | ||
embed_code = p.player[0]["embed_code"]; | ||
$ = cheerio.load(embed_code); | ||
video_url = $('iframe').attr('src'); | ||
if (video_url) { | ||
if (video_url.indexOf('//') === 0) { | ||
video_url = video_url.replace('//', 'http://'); | ||
} | ||
video_domain = video_url.replace('http://', '').replace('https://', '').split(/[/?#]/)[0]; | ||
if (video_domain === "") { | ||
video_domain = video_url; | ||
} | ||
pvideo = "<h1><p>Video: <a href=\"" + video_url + "\">" + video_domain + "</a></p></h1>"; | ||
} | ||
} else { | ||
pvideo = ""; | ||
} | ||
} else { | ||
pvideo = ""; | ||
} | ||
if (p.photos) { | ||
pphotos = p.photos.map(function(photo) { | ||
return "<p><img src=\"" + photo.original_size.url + "\" /></p>"; | ||
}).join(''); | ||
} else { | ||
pphotos = ""; | ||
} | ||
if (p.caption) { | ||
pcap = p.caption; | ||
} else { | ||
pcap = ""; | ||
} | ||
title = p.date.replace(" GMT", ""); | ||
body = ptitle + ptext + pphotos + pvideo + pcap + pbody + pquotesrc + pdesc + psource; | ||
exp = /<iframe.+<\/iframe>/g; | ||
regex = new RegExp(exp); | ||
body = body.replace(regex, ''); | ||
return { | ||
title: title, | ||
body: body, | ||
toc: true | ||
}; | ||
}; | ||
this.fetch = function(tumblrPrefix, cb) { | ||
@@ -57,16 +142,3 @@ this.blogUrl = tumblrPrefix + '.tumblr.com'; | ||
bookDoc.cover = photos[photos.length - 1]; | ||
bookDoc.pages = posts.map(function(p) { | ||
var body; | ||
if (p.photos) { | ||
body = (p.photos.map(function(photo) { | ||
return "<p><img src=\"" + photo.original_size.url + "\" /></p>"; | ||
}).join('')) + p.caption; | ||
} else { | ||
body = p.caption; | ||
} | ||
return { | ||
title: p.caption ? p.caption.replace(/(<([^>]+)>)/ig, "") : "", | ||
body: body | ||
}; | ||
}).filter(function(p) { | ||
bookDoc.pages = posts.map(formatPosts).filter(function(p) { | ||
return p.body != null; | ||
@@ -73,0 +145,0 @@ }); |
{ | ||
"name": "tumblr-2-pe-epub", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "tumblr into pe-epub format", | ||
@@ -12,6 +12,7 @@ "main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/peoples-e/tumblr-2-pe-epub" | ||
"type": "git", | ||
"url": "https://github.com/peoples-e/tumblr-2-pe-epub" | ||
}, | ||
"dependencies": { | ||
"cheerio": "^0.17.0", | ||
"tumblr": "~0.4.1" | ||
@@ -18,0 +19,0 @@ }, |
Sorry, the diff of this file is not supported yet
10967
156
2
+ Addedcheerio@^0.17.0
+ AddedCSSselect@0.4.1(transitive)
+ AddedCSSwhat@0.4.7(transitive)
+ Addedcheerio@0.17.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddom-serializer@0.0.1(transitive)
+ Addeddomelementtype@1.1.3(transitive)
+ Addeddomhandler@2.2.1(transitive)
+ Addeddomutils@1.4.31.5.1(transitive)
+ Addedentities@1.0.01.1.2(transitive)
+ Addedhtmlparser2@3.7.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstring_decoder@0.10.31(transitive)