Created
April 30, 2016 02:24
-
-
Save wizardforcel/f3ccb734e7b5936cd86148df9f021171 to your computer and use it in GitHub Desktop.
Generate archive for my ebook blog
This file contains hidden or 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
var fs = require('fs'); | |
var path = 'D:\\it-ebooks\\source\\_posts'; | |
var files = fs.readdirSync(path); | |
var result = '# 计算机开放电子书汇总\n\n' + | |
'+ [站点](http://it-ebooks.flygon.net/)\n' + | |
'+ [站点源码](https://github.com/it-ebooks/blog)\n\n'; | |
var reTitle = /^title: (.+?)$/m; | |
var reDL = /^[\+\-\*]\s+\[.+?\]\(.+?\)$/mg; | |
for(var i in files) | |
{ | |
var fName = files[i]; | |
if(!fName.endsWith('.md')) | |
continue; | |
console.log(fName); | |
var content = fs.readFileSync(path + '\\' + fName, 'utf-8'); | |
var rmTitle = content.match(reTitle); | |
if(!rmTitle) continue; | |
var title = rmTitle[1]; | |
var pos = content.indexOf('## 在线阅读'); | |
if(pos == -1) { | |
pos = content.indexOf('## 下载地址'); | |
if (pos == -1) continue; | |
} | |
content = content.substring(pos); | |
var links = ''; | |
while(rm = reDL.exec(content)) | |
{ | |
links += rm[0] + '\n'; | |
} | |
if(links == '') | |
continue; | |
result += '## ' + title + '\n\n'; | |
result += links; | |
result += '\n'; | |
} | |
fs.writeFileSync('result.md', result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment