Last active
June 15, 2017 10:04
-
-
Save yuanoook/a6f2f06b4ea39076effc23130ef5c696 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var $ = require('cheerio'); | |
var sh = require('child_process').execSync; | |
var indexs = []; | |
for(let i=1; i<=221; i++) indexs.push(i); | |
var combo_body = indexs.reduce((prev, index) => { | |
var content = ''; | |
try { | |
content = fs.readFileSync(`./episodes/episode${index}.html`); | |
} catch(e) { | |
return prev; | |
} | |
var doc = $.load(content)('.post'); | |
doc.find('header a').attr('href', 'javascript:;'); | |
doc.find('.article-dateline a').attr('href', 'https://pronuncian.com/podcasts/episode'+index); | |
doc.find('p a').toArray().forEach(a => { | |
a.attribs.href = a.attribs.href.replace( | |
/^http:\/\/www\.pronuncian\.com\/podcast\.aspx\?Episode\=(.*)$/, | |
"https://pronuncian.com/podcasts/episode$1" | |
); | |
if(a.attribs.href.indexOf('/') !== 0) return; | |
a.attribs.href = 'https://pronuncian.com' + a.attribs.href; | |
}); | |
doc.find('a').attr('target', '_blank'); | |
doc.find('.article-dateline-above-title').remove(); | |
var header = $.html(doc.find('header')); | |
var main = $.html(doc.find('p')); | |
return `${prev}<section>${header}${main}</section>`; | |
}, ''); | |
combo_body = `<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"> | |
<title>Pronuncian.Podcasts.Scripts</title> | |
<style> | |
body { | |
font-size: 18px; | |
line-height: 1.5; | |
} | |
h1 { | |
font-size: 20px; | |
} | |
p, | |
span { | |
display: none; | |
} | |
section.open p { | |
display: block; | |
} | |
section.open span{ | |
display: inline; | |
} | |
</style> | |
<script> | |
window.onclick = function(e) { | |
var target; | |
if (target = closest(e.target, 'h1')) { | |
var section = closest(target, 'section'); | |
section && section.classList.toggle('open'); | |
} | |
function closest(dom, tag) { | |
if (!dom) return null; | |
if (is(dom, tag)) return dom; | |
return closest(dom.parentElement, tag); | |
} | |
function is(dom, tag) { | |
return dom.tagName === tag.toUpperCase(); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
${combo_body} | |
</body> | |
</html>`; | |
fs.writeFileSync('./episodes.combo.html', combo_body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment