UNPKG

700 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3
4// 读取当前路径下的文件,方便服务器404的时候导航
5module.exports = function (fullUrl) {
6
7 let files, content = fullUrl;
8 try {
9 files = fs.readdirSync(fullUrl);
10 } catch (e) {
11 content = path.resolve(fullUrl, '../');
12 files = fs.readdirSync(content);
13 }
14
15 let list = [];
16
17 for (let i in files) {
18 let isFolder = fs.lstatSync(path.join(content, files[i])).isDirectory();
19
20 // 保存起来
21 list.push({
22
23 // 文件类型
24 type: isFolder ? "folder" : "file",
25
26 // 地址
27 url: "./" + files[i] + (isFolder ? "/" : "")
28
29 });
30
31 }
32
33 return list;
34};
\No newline at end of file