-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
186 lines (175 loc) · 6.79 KB
/
index.html
File metadata and controls
186 lines (175 loc) · 6.79 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,=">
<link href="css/antd.min.css" rel="stylesheet" type="text/css"/>
<link href="css/highlight-hybrid.min.css" rel="stylesheet" type="text/css"/>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script src="js/vue.min.js"></script>
<script src="js/antd.min.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/marked.min.js"></script>
<script src="js/highlight.min.js"></script>
<script src="js/vue-dash-event.min.js"></script>
</head>
<body>
<div id="app">
<a-layout>
<!---------- 头部区域开始 ---------->
<a-layout-header class="header">
<div class="logo"></div>
<div class="title">{{title}}</div>
</a-layout-header>
<!---------- 头部区域结束 ---------->
<a-divider class="divider"></a-divider>
<a-layout>
<!---------- 导航菜单开始 ---------->
<a-layout-sider width="300" class="sider">
<a-menu
mode="inline"
:open-keys="menu.open"
:selected-keys="menu.selected"
v-on:open-change="openMenu"
v-on:select="selectMenu"
>
<a-sub-menu v-for="(sub,index) in menu.data" :key="`${index.toString()}`">
<span slot="title"><a-icon :type="sub.icon"></a-icon>{{sub.title}}</span>
<a-menu-item v-for="item in sub.child" :key="item.doc" @click="getDoc(item.doc, null, true)">
{{item.title}}
</a-menu-item>
</a-sub-menu>
</a-menu>
</a-layout-sider>
<!---------- 导航菜单结束 ---------->
<!---------- 正文区域开始 ---------->
<a-layout-content v-html="content" class="content"></a-layout-content>
<!---------- 正文区域结束 ---------->
<!---------- 锚点区域开始 ---------->
<a-layout-sider class="anchor">
<a-anchor>
<a-anchor-link
v-for="item in anchor"
:href="item.href"
:title="item.title"
:style="`margin-left:${item.level-1}em`">
</a-anchor-link>
</a-anchor>
</a-layout-sider>
<!---------- 锚点区域结束 ---------->
<!---------- 回到顶部开始 ---------->
<a-back-top>
<div class="ant-back-top-inner">
<a-icon type="arrow-up"></a-icon>
</div>
</a-back-top>
<!---------- 回到顶部结束 ---------->
</a-layout>
</a-layout>
</div>
<script>
Vue.use(window['vue-dash-event']);
new Vue({
el: '#app',
data: {
title: '',
menu: {
data: [],
open: [],
selected: [],
},
anchor: [],
content: '',
},
methods: {
init: function (setHistory) {
let doc = this.getQuery('doc');
doc = doc ? doc : this.menu.data[0].child[0].doc;
this.getDoc(doc, window.location.hash, setHistory); // 读取文档
this.menu.selected = [doc];
},
// 读取文档
getDoc: function (doc, hash, setHistory) {
let _this = this;
if (_this.menu.selected[0] === doc) {
return;
}
_this.anchor = [];
axios.get(`doc/${doc}.md?t=${(new Date()).getTime()}`).then(function (rsp) {
// 代码高亮
marked.setOptions({
highlight: function (code) {
return hljs.highlightAuto(code).value;
}
});
// 设置渲染
const renderer = new marked.Renderer();
renderer.link = _this.rendererLink();
renderer.heading = _this.rendererHeading();
_this.content = marked(rsp.data, {renderer: renderer});
// 路由跳转
_this.$nextTick(() => {
if (setHistory) {
history.pushState({}, '', `?doc=${doc}`);
}
if (hash) {
document.getElementById(decodeURI(hash).substring(1)).scrollIntoView();
location.hash = hash;
} else {
scrollTo({top: 0, behavior: 'smooth'});
}
})
});
},
// 渲染链接(新窗口打开)
rendererLink: function () {
return function (href, title, text) {
let out = `<a target="_blank" href="${href}"`;
out += title ? ` title="${title}"` : '';
return `${out}>${text}</a>`;
}
},
// 渲染标题(加入锚点链接)
rendererHeading: function () {
let _this = this;
return function (text, level) {
_this.anchor.push({title: text, href: `#${text}`, level: level});
return `<h${level} id="${text}">${text}</h${level}>`;
};
},
// 读取 GET 参数
getQuery: function (name) {
let query = window.location.search.substring(1).split('&');
for (let item of query) {
let arr = item.split('=');
if (arr[0] === name) {
return arr[1];
}
}
},
// 打开菜单
openMenu(keys) {
this.menu.open = keys;
},
// 选中菜单
selectMenu(item) {
this.menu.selected = [item.key];
}
},
mounted: function () {
var _this = this;
axios.get(`config.json?t=${(new Date()).getTime()}`).then(function (rsp) {
document.title = _this.title = rsp.data.title; // 设置网页标题
_this.menu.data = rsp.data.menu; // 设置导航菜单
_this.menu.open = Object.keys(_this.menu.data); // 展开所有一级菜单
_this.init(true);
});
onpopstate = function () {
_this.init(false);
};
}
});
</script>
</body>
</html>