加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
genSidebar.js 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
cq.li@szsolar.cn 提交于 2021-11-09 16:44 . test
var sidebarTxt='* [首页](/)\n';
var path = require('path');
var curPath = path.resolve('./');
function walkSync(currentDirPath, prefixBlank, callback) {
var fs = require('fs'),
path = require('path');
fs.readdirSync(currentDirPath).forEach(function (name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory() && ".git"!=path.basename(filePath) && '_' != path.basename(filePath).substr(0,1)) {
sidebarTxt += prefixBlank +'* ' +path.basename(filePath)+'\n';
walkSync(filePath, prefixBlank+' ', callback);
}
});
}
walkSync(curPath,'', function(filePath, stat) {
if(".md" == path.extname(filePath).toLowerCase()
&& '_' != path.basename(filePath).substr(0,1)
&& 'README.md' != path.basename(filePath)){
var relativeFilePath = filePath.substr(curPath.length);
//console.log("file:"+ path.basename(filePath).slice(1));
var itemText = relativeFilePath.substr(1, relativeFilePath.length-4);
while(itemText.indexOf('/')>0){
itemText = itemText.substr(itemText.indexOf('/')+1);
sidebarTxt += ' ';
}
sidebarTxt += '- ['+itemText+']('+relativeFilePath+')\n';
}
//console.log("file:"+ +path.extname(filePath));
});
var path = require('path');
var fs = require('fs');
fs.copyFile(path.resolve('./')+"/_sidebar.md",path.resolve('./')+"/_sidebar.md.bak",function(err){
if(err) throw new Error('something wrong was happended') });
//console.log(path.resolve('./')+"/_sidebar.md");
console.log(sidebarTxt);
fs.writeFile(path.resolve('./')+'/_sidebar.md', sidebarTxt,function(err){
if(err){
console.error(err);
}
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化