-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
151 lines (151 loc) · 3.71 KB
/
index.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="./src/public/favicon.svg" />
<link rel="stylesheet" href="" />
<title><%- title %></title>
<style type="text/css">
:root {
--background-color: rgba(255, 69, 0, 0.1);
--font-size-big: 18px;
--font-size-mid: 16px;
--font-size-small: 15px;
--font-color: #333333;
--font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica, Arial, sans-serif';
--front-color: rgba(255, 69, 0);
}
* {
margin: 0;
padding: 0;
}
html {
width: 100vw;
height: 100vh;
}
body {
width: 100%;
font-family: var(--font-family);
}
header {
width: 100%;
height: 200px;
line-height: 100px;
display: flex;
justify-content: center;
align-items: center;
color: var(--font-color);
font-size: 40px;
}
header > .label {
margin-left: 10px;
}
.content {
column-gap: 20px;
column-count: 4;
column-fill: balance;
padding: 20px;
break-inside: avoid;
-webkit-column-break-inside: avoid;
padding-left: 8%;
}
main > .card {
margin: 0 0 50px 0;
overflow: hidden;
}
figcaption {
height: 25px;
line-height: 25px;
font-size: var(--font-size-small);
color: var(--front-color);
}
figcaption::before {
content: '\2022';
display: inline-block;
width: 14px;
font-family: 'entypo', sans-serif;
}
main > .card > figcaption {
font-size: var(--font-size-big);
margin-bottom: 20px;
padding-left: 0;
list-style: none;
}
main > .card > figcaption::before {
content: none;
}
a {
height: 25px;
line-height: 25px;
display: block;
color: var(--font-color);
font-size: var(--font-size-small);
margin: 5px 0;
padding-left: 14px;
}
a:hover {
transition: ease-in 100ms;
text-decoration-color: var(--front-color);
}
main > .card > a {
padding-left: 0;
}
</style>
</head>
<body>
<header>
<object data="./src/public/favicon.svg" width="48" height="48"></object>
<label class="label"><%- title %></label>
</header>
<main class="content"></main>
<script type="text/javascript">
const fragEle = document.createDocumentFragment();
const { demoList } = JSON.parse(`<%- params %>`);
// 创建节点卡片组件
function createCard(node, root) {
const { path, name, index, children } = node;
if (children.length) {
// dir node
const figEle = document.createElement('figure');
figEle.className = 'card';
figEle.setAttribute('key', index);
figEle.innerHTML = `<figcaption>${name}</figcaption>`;
root.appendChild(figEle);
children.forEach(child => {
createCard(child, figEle);
});
} else {
// file node
const aEle = document.createElement('a');
aEle.setAttribute('key', index);
aEle.setAttribute('href', path);
aEle.setAttribute('target', '_blank');
aEle.innerHTML = `${name.substring(0, name.indexOf('.'))}`;
root.appendChild(aEle);
}
return root;
}
// 根据目录树展示所有卡片
const cardsEle = document.createDocumentFragment();
const mainNode = {
name: 'Main',
children: [],
};
const nodes = []; // demos根目录下所有文件归为Main节点
demoList.children.forEach(n => {
if (n.children.length) {
nodes.push(n);
} else {
mainNode.children.push(n);
}
});
nodes.push(mainNode);
nodes.forEach(n => {
createCard(n, cardsEle);
});
document.querySelector('.content').appendChild(cardsEle);
</script>
</body>
</html>