-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (25 loc) · 840 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 用于首页的链接的url;
* 使用nodejs开发,使用path, fs 模块
* */
const fs = require('fs');
const path = require("path");
const dirs = fs.readdirSync(path.join(__dirname));
const data = [];
dirs.forEach(dir => {
const dirPath = path.join(__dirname, dir);
if(fs.statSync(dirPath).isDirectory() && dir !== '.git') {
const subDirs = fs.readdirSync(path.join(__dirname, dir));
subDirs.forEach(file => {
console.log("subDir", file);
if(file.indexOf('.html') > -1) {
data.push({
title: dir,
link: `./${dir}/${file}`
})
}
})
}
});
fs.writeFileSync(path.join(__dirname, 'data.js'), `var data=`);
fs.appendFileSync(path.join(__dirname, 'data.js'), JSON.stringify(data), 'utf8');