-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
79 lines (64 loc) · 2.43 KB
/
index.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const path = require('path');
const utils = require('./utils');
class SidebarGen {
constructor () {
};
//動かない
getSidebarItem (targetdir) {
let workingdir = './docs';
let files = utils.getFiles(workingdir, targetdir);
return utils.getFilepaths(files, targetdir).map((path) => {
return "[" + path + " ]";
}).join();
};
// サイドバーアイテムの作成 メイン
getSidebarGroup (targetdir = '/', title = '', isCollapsable = true) {
let workingdir = './docs';
let files = utils.getFiles(workingdir, targetdir);
let grouptitle = utils.toTitle(title, targetdir);
//サイドバーアイテムの作成
let directoryGroup = {
// グループリストタイトル
title: grouptitle,
// グループリスト展開有無
collapsable: isCollapsable,
// ディレクトリ配下のファイルリスト作成
children: utils.getFilepaths(files, targetdir)
};
return directoryGroup;
};
// サイドバーアイテムの作成 メイン
getSidebarList (isCollapsable = true) {
//rootパス用
let root = ['']
//vuepressルートディレクトリ
let workingdir = './docs';
//root直下のファイル群はグループ化しないためファイルを単品で表示する。
//root直下のファイル一覧取得
let rootfiles = utils.getRootFileItems(workingdir);
//ファイルパスの生成
let rootItems = rootfiles.map((file) => {
//return '/' + file;
return path.join(file);
});
//ディレクトリ一覧の取得
let directores = utils.getDirectores(workingdir);
//サイドバーアイテムの作成(ディレクトリ毎)
let directoryGroups = directores.map((directory) => {
//サイドバーアイテムの作成
return {
// グループリストタイトル
title: directory,
// グループリスト展開有無
collapsable: isCollapsable,
// ディレクトリ配下のファイルリスト作成
children: utils.getFileitems(workingdir, directory)
};
});
// root直下のファイル群とroot配下のディレクトリ群を結合してサイドバーのアイテムとする。
// ※root直下のREADME.mdについては'/'で表現される。
let sidebarList = root.concat(rootItems, directoryGroups);
return sidebarList;
};
}
module.exports = new SidebarGen();