From 9c374238109e317b51ee1c4b5f0784ab7cfd2afb Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Thu, 1 Dec 2016 02:28:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=94=9F=E6=88=90=E6=8F=90?= =?UTF-8?q?=E5=89=8D=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/compile.js | 68 ++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/build/compile.js b/build/compile.js index 5dcb7270ce..b5fa5e84ed 100644 --- a/build/compile.js +++ b/build/compile.js @@ -88,39 +88,41 @@ CreateDatajs('./.deploy/js/dt.js',function(dt_path,arr){ ReadTmpToHTML('/template/details.ejs', dep+'.html' ,md_path+'.md', itm) }); + console.log(success(" → "),arr.length) + }) -// 监听实时编译 -watch.watchTree(path.join(path.dirname(__dirname),'/'), function (f, curr, prev) { - if (typeof f == "object" && prev === null && curr === null) { - console.log(success(" → :watching ") + '/template/'); - // Finished walking the tree - } else if (prev === null) { +// // 监听实时编译 +// watch.watchTree(path.join(path.dirname(__dirname),'/'), function (f, curr, prev) { +// if (typeof f == "object" && prev === null && curr === null) { +// console.log(success(" → :watching ") + '/template/'); +// // Finished walking the tree +// } else if (prev === null) { - // f is a new file - } else if (curr.nlink === 0) { - // f was removed - } else { +// // f is a new file +// } else if (curr.nlink === 0) { +// // f was removed +// } else { - if(/\.styl$/.test(f)){ - CreateStyl('/template/styl/index.styl','/.deploy/css/index.css') - }else if(/\.js$/.test(f)){ +// if(/\.styl$/.test(f)){ +// CreateStyl('/template/styl/index.styl','/.deploy/css/index.css') +// }else if(/\.js$/.test(f)){ - CreateJS('/template/js/index.js','/.deploy/js/index.js') +// CreateJS('/template/js/index.js','/.deploy/js/index.js') - }else if(/\.ejs$/.test(f)){ - // 首页生成 - ReadTmpToHTML('/template/index.ejs','/.deploy/index.html'); - ReadTmpToHTML('/template/list.ejs','/.deploy/list.html'); +// }else if(/\.ejs$/.test(f)){ +// // 首页生成 +// ReadTmpToHTML('/template/index.ejs','/.deploy/index.html'); +// ReadTmpToHTML('/template/list.ejs','/.deploy/list.html'); - }else if(/\.md$/.test(f)){ - var mdp = f.replace(path_root,''); - var dep = path.join('/.deploy/',mdp); - ReadTmpToHTML('/template/details.ejs',dep.replace('.md','.html'),mdp); - } - } -}) +// }else if(/\.md$/.test(f)){ +// var mdp = f.replace(path_root,''); +// var dep = path.join('/.deploy/',mdp); +// ReadTmpToHTML('/template/details.ejs',dep.replace('.md','.html'),mdp); +// } +// } +// }) function CreateJS(from_path,to_path){ @@ -220,6 +222,7 @@ function CreateDatajs(dt_path,callback){ if(!exists(path_md)) return console.log("\n → error: 文件夹 "+path_md+" 不存在 \n ") // 获取 markdown 目录的集合 var path_arr = readMDSync(path_md); + path_arr = sortLength(path_arr); var indexes = [] path_arr.forEach(function(md_path,i){ var json = {} @@ -243,6 +246,21 @@ function CreateDatajs(dt_path,callback){ }); } +// 按长度排序 +function sortLength(arr){ + var compare = function (x, y) {//比较函数 + x = path.basename(x,'.md'); + y = path.basename(y,'.md'); + if (x.length < y.length) { + return -1; + } else if (x.length > y.length) { + return 1; + } else { + return 0; + } + } + return arr.sort(compare) +} // 同步循环创建所有目录 resolvePath function mkdirsSync(dirpath, mode, callback) {