Last active
September 2, 2016 05:31
-
-
Save tadfmac/c5a15f63b4f22be2f80e6c335dec1763 to your computer and use it in GitHub Desktop.
指定path配下にある readme.mdをindex.htmlに変換
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
/* | |
markdown->html化 | |
Usage : node out.js <対象path> | |
※<対象path>配下に設置してある readme.mdを再帰的にindex.htmlに変換します。 | |
※<対象path>/github.css を適用します。 | |
あらかじめ node.js、 pandocのインストールを行っておいてください | |
*/ | |
var fs = require('fs'); | |
var execSync = require('child_process').execSync; | |
var cssname = "github.css"; | |
var rootpath = process.argv[2]; // 対象path | |
function readpath(path,depth){ | |
fs.readdir(path,function(err,files){ | |
if(files.length != 0){ | |
for(var cnt=0;cnt < files.length; cnt++){ | |
console.dir(files[cnt]); | |
var checkpath = path+'/'+files[cnt]; | |
if(fs.statSync(checkpath).isDirectory()){ | |
readpath(checkpath,depth+1); | |
} | |
if(files[cnt] == 'readme.md'){ | |
var htmlpath = 'index.html'; | |
var csspstr = cssname; | |
if(depth > 0){ | |
for(var cnt2=0;cnt2 < depth;cnt2++){ | |
csspstr = "../"+csspstr; | |
} | |
}else{ | |
csspstr = "./"+csspstr; | |
} | |
console.log("css:"+csspstr); | |
var param = "pandoc readme.md -s --self-contained -t html5 -c "+csspstr+" -o index.html"; | |
execSync(param,{cwd:path}); | |
} | |
} | |
} | |
}); | |
} | |
readpath(rootpath,0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment