-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
83 lines (70 loc) · 2.02 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
80
81
82
"use strict"
const fs = require('fs')
const path = require('path')
const child_process = require('child_process')
const file = require('file')
const createSourceList = (node)=>{
var s = "";
Object.keys(node).forEach( (each)=>{
var value = node[each];
if ( typeof value == 'object' ) {
//skip
} else {
console.log( "file", each, value );
s = s + '<li><a target="_self" href="/' + value + '">' + each + "</a></li>";
}
} )
Object.keys(node).forEach( (each)=>{
var value = node[each];
if ( typeof value == 'object' ) {
console.log( "dir", each, value );
s = s + "<li>" + each + "/<ul>";
s = s + createSourceList( value );
s = s + "</ul>";
}
} )
return s;
}
module.exports = {
hooks: {
'page': function (page) {
const dir = path.dirname( page.path );
const pomXml = path.join( dir, "pom.xml" );
if ( ! fs.existsSync( pomXml ) ) {
return page;
}
const srcDir = path.join( dir, "src" );
if ( ! fs.existsSync( srcDir ) ) {
return page;
}
const root = {};
const all = {};
all[dir] = root;
console.log( "walk", dir );
file.walkSync( dir, (curPath, dirList, fileList)=>{
console.log( "walk", curPath, dirList, fileList );
var node = all[curPath];
if ( ! node ) {
node = {};
all[curPath] = node;
}
dirList.forEach( (each)=>{
node[each] = {};
all[ path.join( curPath, each ) ] = node[each];
} )
fileList.filter( (e)=>{
return ! e.endsWith( '.iml') && ! e.endsWith( '.adoc' );
}).forEach( (each)=>{
var fileLink = path.join( curPath, each );
console.log( each, fileLink );
node[each] = fileLink;
});
//files.push( item );
} )
const list = '<h2>Sources</h2><ul class="sourcelist">' + createSourceList( root ) + "</ul>";
page.content = page.content + list;
console.log( list );
return page
}
}
}