为你的hexo博客添加导航页

今天来说下如何在hexo博客中添加静态导航页面!(针对主题文件格式为ejs的)

首先看下效果吧!(以matery主题为例)

借用框架师的效果图

  • 首先新建页面,执行下面的命令
1
hexo new page navigate
  • 修改navigate目录下的index.md的格式
1
2
3
4
5
6
---
title: 导航
date: 2020-05-09 11:19:14
type: "navigate"
layout: "navigate"
---
  • 在主题配置文件中添加导航
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
# main menu navigation url and icon
# 配置菜单导航的名称、路径和图标icon.
menu:
Index:
url: /
icon: fas fa-home
统计:
url: /
icon: fas fa-sitemap
children:
- name: 分类
url: /categories
icon: fas fa-bookmark
- name: 标签
url: /tags
icon: fas fa-tags
- name: 归档
url: /archives
icon: fas fa-archive
About:
url: /about
icon: fas fa-address-card
Contact:
url: /contact
icon: fas fa-comments
友人帐:
url: /friends
icon: fas fa-share-alt
赞助墙:
url: /sponsor
icon: fa fa-credit-card
导航:
url: /navigate
icon: fas fa-location-arrow
  • matery/layout下新建navigate.ejs
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<div class="navi-height bg-cover pd-header ">
<div class=" link-box container">
<!-- 搜索框 -->
<div class="baidu baidu-2 large-screen">
<form name="f" action="https://www.baidu.com/" target="_blank">
<div id="Select-2">
<div class="Select-box-2" id="baidu">
<ul style="height: 46px;">
<li class="this_s">百 · 度</li>
<li class="bing_s">必 · 应</li>
<li class="google_s">谷 · 歌</li>
<li class="baidu_s">百 · 度</li>
</ul>
</div> <input name="wd" id="kw-2" maxlength="100" autocomplete="off" type="text">
</div>
<div class="qingkong" id="qingkong" title="清 · 空" style="display: none;">x</div> <input value="搜 · 索"
id="su-2" type="submit">
<ul class="keylist"></ul>
</form>
</div> <!-- 链接 -->
<div class="row tags-posts ">
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">娱乐 · 影视</div>
<ul class="jj-list-con">
<li><a href="https://www.jd.com/" class="link-3" target="_blank">京东</a>
<li><a href="https://www.taobao.com/" class="link-3" target="_blank">淘宝</a></li>
<li><a href="https://www.tmall.com/" class="link-3" target="_blank">天猫</a></li>
</li>
<li><a href="https://v.qq.com/" class="link-3" target="_blank">腾讯视频</a></li>
<li><a href="http://www.iqiyi.com/" class="link-3" target="_blank">爱奇艺</a></li>
<li><a href="https://www.bilibili.com/" class="link-3" target="_blank">哔哩哔哩</a> </li>
<li><a href="https://music.163.com/" class="link-3" target="_blank">网易云音乐</a></li>
<li><a href="https://y.qq.com/" class="link-3" target="_blank">QQ音乐</a></li>
<li><a href="http://www.kugou.com/" class="link-3" target="_blank">酷狗音乐</a></li>
</ul>
</div>
</div>
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">社区 · Code</div>
<ul class="jj-list-con">
<li><a href="https://www.mobaijun.com/contact/" class="link-3" target="_blank">留言</a></li>
<li><a href="https://github.com/" class="link-3" target="_blank">GitHub</a></li>
<li><a href="https://coding.net/" class="link-3" target="_blank">Coding</a></li>
<li><a href="https://juejin.im/" class="link-3" target="_blank">掘金</a></li>
<li><a href="https://gitee.com/" class="link-3" target="_blank">码云</a></li>
<li><a href="https://www.csdn.net/" class="link-3" target="_blank">CSDN</a></li>
<li><a href="https://www.jianshu.com/" class="link-3" target="_blank">简书</a></li>
<li><a href="https://segmentfault.com/" class="link-3" target="_blank">思否</a></li>
<li><a href="https://cloud.tencent.com/developer/" class="link-3" target="_blank">云+社区</a></li>
</ul>
</div>
</div>
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">实用 · 工具</div>
<ul class="jj-list-con">
<li><a href="https://mdnice.com/" class="link-3" target="_blank">Nice编辑器</a></li>
<li><a href="https://translate.google.cn/" class="link-3" target="_blank">谷歌翻译</a></li>
<li><a href="https://www.uupoop.com/" class="link-3" target="_blank">在线PS</a></li>
<li><a href="https://www.processon.com/" class="link-3" target="_blank">思维导图</a></li>
<li><a href="https://wallhaven.cc/" class="link-3" target="_blank">超清壁纸</a></li>
<li><a href="https://cli.im/" class="link-3" target="_blank">二维码</a></li>
<li><a href="http://www.yinfans.me/" class="link-3" target="_blank">音范思</a></li>
<li><a href="https://www.52pojie.cn/" class="link-3" target="_blank">吾爱破解</a></li>
<li><a href="https://my.openwrite.cn/" class="link-3" target="_blank">OW分发</a></li>
</ul>
</div>
</div>
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">编程 · 学习</div>
<ul class="jj-list-con">
<li><a href="https://www.oschina.net/" class="link-3" target="_blank">开源中国</a></li>
<li><a href="https://htmldog.com/" class="link-3" target="_blank">HTML狗</a></li>
<li><a href="https://www.icourse163.org/" class="link-3" target="_blank">中国大学慕课</a></li>
<li><a href="https://www.imooc.com/" class="link-3" target="_blank">慕课网</a></li>
<li><a href="http://www.wxapp-union.com/" class="link-3" target="_blank">小程序</a></li>
<li><a href="https://www.runoob.com/" class="link-3" target="_blank">菜鸟教程</a></li>
<li><a href="https://blog.51cto.com/" class="link-3" target="_blank">51CTO</a></li>
<li><a href="https://www.shiyanlou.com/library/" class="link-3" target="_blank">实验楼</a></li>
<li><a href="https://spring.io/" class="link-3" target="_blank">Spring</a></li>
</ul>
</div>
</div>
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">资讯 · 趋势</div>
<ul class="jj-list-con">
<li><a href="https://www.huxiu.com/" class="link-3" target="_blank">虎嗅</a></li>
<li><a href="https://insights.stackoverflow.com/" class="link-3" target="_blank">技术调查</a></li>
<li><a href="http://www.asciiworld.com/" class="link-3" target="_blank">摸鱼</a></li>
<li><a href="https://sspai.com/" class="link-3" target="_blank">少数派</a></li>
<li><a href="https://zh.wikihow.com/" class="link-3" target="_blank">WikeHom</a></li>
<li><a href="https://www.awesomes.cn/rank?sort=hot" class="link-3" target="_blank">前端趋势</a></li>
<li><a href="https://github-trending.com/" class="link-3" target="_blank">GitHub趋势</a></li>
<li><a href="https://www.tiobe.com/" class="link-3" target="_blank">编程趋势</a></li>
<li><a href="https://trends.google.com/" class="link-3" target="_blank">Google趋势</a></li>
</ul>
</div>
</div>
<div class="col s12 m6 l4 friend-div" data-aos="zoom-in-up">
<div class="card">
<div class="jj-list-tit">搜索 · 其他</div>
<ul class="jj-list-con">
<li><a href="https://ac.scmor.com/" class="link-3" target="_blank">谷歌镜像</a></li>
<li><a href="http://www.pansoso.com/" class="link-3" target="_blank">网盘搜索</a></li>
<li><a href="http://tool.mkblog.cn/music/" class="link-3" target="_blank">音乐搜索</a></li>
<li><a href="https://www.dytt8.net/" class="link-3" target="_blank">电影天堂</a></li>
<li><a href="https://carbon.now.sh/" class="link-3" target="_blank">代码图片</a></li>
<li><a href="https://www.zhipin.com/" class="link-3" target="_blank">Boos</a></li>
<li><a href="https://fontawesome.com/" class="link-3" target="_blank">图标库</a></li>
<li><a href="https://www.qvdv.com/tools/qvdv-guid.html" class="link-3" target="_blank">在线工具</a>
</li>
<li><a href="http://zhongguose.com/" class="link-3" target="_blank">中国色</a></li>
</ul>
</div>
</div>
</div>
<script> /*选择搜索引擎*/ $('.Select-box ul').hover(function () { $(this).css('height', 'auto') }, function () { $(this).css('height', '40px') }); $('.Select-box-2 ul').hover(function () { $(this).css('height', 'auto') }, function () { $(this).css('height', '46px') }); $('.Select-box li').click(function () { var _tihs = $(this).attr('class'); var _html = $(this).html(); if (_tihs == 'baidu_s') { _tihs = 'https://www.baidu.com/s'; _name = 'wd'; } if (_tihs == 'google_s') { _tihs = 'https://www.google.com/search'; _name = 'q'; } if (_tihs == 'bing_s') { _tihs = 'https://www.bing.com/search'; _name = 'q'; } $('.baidu form').attr('action', _tihs); $('.this_s').html(_html); $('#kw').attr('name', _name); $('.Select-box ul').css('height', '40px') }); $('.Select-box-2 li').click(function () { var _tihs = $(this).attr('class'); var _html = $(this).html(); if (_tihs == 'baidu_s') { _tihs = 'https://www.baidu.com/s'; _name = 'wd'; } if (_tihs == 'google_s') { _tihs = 'https://www.google.com/search'; _name = 'q'; } if (_tihs == 'bing_s') { _tihs = 'https://www.bing.com/search'; _name = 'q'; } $('.baidu form').attr('action', _tihs); $('.this_s').html(_html); $('#kw-2').attr('name', _name); $('.Select-box-2 ul').css('height', '48px') }); //清空输入框内容 $('.qingkong').click(function () { cls(); $(this).css('display', 'none') }); function cls() { var sum = 0; var t = document.getElementsByTagName("INPUT"); for (var i = 0; i < t.length; i++) { if (t[i].type == 'text') { ++sum; t[i].value = "";//清空 } } } //清空输入框按钮的显示和隐藏 function if_btn() { var btn_obj = document.getElementById("kw") || document.getElementById("kw-2"); var cls_btn = document.getElementById("qingkong"); var btn_obj_val; var times; //当元素获得焦点时 if (btn_obj == '' || btn_obj == null) { return false; //如果没有找到这个元素,则将函数返回,不继续执行 } btn_obj.onfocus = function () { times = setInterval(function () { btn_obj_val = btn_obj.value; if (btn_obj_val != 0) { cls_btn.style.display = "block"; } else { cls_btn.style.display = "none"; } }, 200); } //元素失去焦点时 btn_obj.onblur = function () { clearInterval(times); } } </script>
</div>
</div>
<style>
* {
margin: 0;
padding: 0;
font-family: "微软雅黑"
}
ul,li,h1,h2,h3,h4,h5,h6,p,form,dl,dt,dd {
margin: 0px;
padding: 0px;
font-size: 14px;
font-weight: normal;
}

img {
border-style: none;
}

li {
list-style: none;
float: left
}

a {
text-decoration: none
}

.card {
background-color: rgba(25, 240, 229, 0);
width: 96%;
margin-left: 2%
}

.baidu {
float: left;
margin-left: 100px;
}

.baidu form {
position: relative
}

.Select-box ul {
height: 40px;
position: absolute;
left: -1px;
top: 0px;
z-index: 9999;
background: #FFF;
border: 1px solid #ccc;
border-top: none;
overflow: hidden
}

.Select-box li {
width: 60px;
line-height: 40px;
font-size: 14px;
color: #484848;
border: 0;
cursor: pointer;
}

.Select-box li:hover {
background: #3385ff;
color: #FFF;
}

.Select-box .this_s {
color: #317ef3;
}

.Select-box .this_s:hover {
background: #FFF;
color: #317ef3;
}

.qingkong {
position: absolute;
right: 120px;
top: 12px;
width: 18px;
height: 18px;
background: rgba(0, 0, 0, 0.1);
border-radius: 18px;
line-height: 16px;
color: #666666;
cursor: pointer;
text-align: center;
font-size: 14px;
display: none;
}

.qingkong:hover {
background: rgba(0, 0, 0, 0.2);
}

.qingkong:active {
background: rgba(0, 0, 0, 0.3);
}

.baidu-2 {
width: 100%;
height: 110px;
margin: 0 auto;
background: none;
padding-top: 50px;
}

.baidu-2 form {
width: 520px;
margin: 0 auto;
}

.baidu-2 input {
padding: 13px 8px;
opacity: 0.9;
font-size: 15px;
}

#Select-2 {
float: left;
}

.Select-box-2 {
text-align: center;
float: left;
position: relative;
}

.Select-box-2 ul {
height: 46px;
position: absolute;
left: 0px;
top: 1px;
z-index: 9999;
background: rgba(255, 255, 255, 0.9);
border: 1px solid #ccc;
border-top: none;
overflow: hidden
}

.Select-box-2 li {
width: 60px;
line-height: 46px;
font-size: 15px;
color: #484848;
border: 0;
cursor: pointer;
}

.Select-box-2 li:hover {
background: #3385ff;
color: #FFF;
}

.Select-box-2 .this_s {
color: #317ef3;
}

.Select-box-2 .this_s:hover {
background: none;
color: #317ef3;
}

#kw-2 {
width: 335px;
outline: 0;
border: 1px solid #ccc;
background: rgba(255, 255, 255, 0.2);
color: #000000;
padding-left: 70px;
font-weight: bold;
}

/*修改搜索框样式*/
#su-2 {
width: 90px;
background: blue;
border: none;
border-top: #3385ff 1px solid;
border-bottom: 1px solid #2d78f4;
color: #FFF;
cursor: pointer;
/*去轮廓阴影*/
outline: none;
}

/*光标移动到搜索框颜色*/
#su-2:hover {
background: blue;
border-bottom: 1px solid blue;
}

#su-2:active {
background: blue;
box-shadow: inset 1px 1px 3px blue;
-webkit-box-shadow: inset 1px 1px 3px blue;
}

.jj-list-tit {
font-size: 16px;
line-height: 25px;
color: #ffffff;
width: 100%;
padding-left: 38.5%;
}

.jj-list-con {
overflow: hidden;
margin: 0 auto
}

/*控制网站列表间距*/
.jj-list-con li {
width: 31.333%;
margin: 1%;
}

.link-3 {
display: block;
background: rgba(0, 0, 0, .35);
color: #FFF;
font-size: 13px;
text-align: center;
line-height: 35px;
padding: 4px 0;
border-radius: 2px;
transition: all 0.2s
}

.link-3:hover {
background: rgba(0, 0, 0, .45);
font-size: 15px;
font-weight: bold
}

/*1栏 小于584*/
@media only screen and (max-width: 584px) {
.navi-height {
height: 1300px;
}

.link-box {
margin-top: 5%;
}

.large-screen {
display: none;
}
}

/* 2栏 大于584 小于993px */
@media only screen and (min-width: 584px) and (max-width: 993px) {
.navi-height {
height: 800px;
}

.link-box {
margin-top: 5%;
}

.large-screen {
display: none;
}
}

/*3栏 大于993px*/
@media only screen and (min-width: 993px) {
.navi-height {
position: absolute;
width: 100%;
height: 100%;
}
}

/* 隐藏footer */
.page-footer {
display: none;
}
</style>
<% if (theme.banner.enable) { %>
<script>
// 每天切换 banner 图. Switch banner image every day.
var bannerUrl = "<%- theme.jsDelivr.url %><%- url_for('/medias/banner/') %>" + new Date().getDay() + '.jpg';
$('.bg-cover').css('background-image', 'url(' + bannerUrl + ')');
</script>
<% } else { %>
<script>
$('.bg-cover').css('background-image', 'url(<%- theme.jsDelivr.url %><%- url_for('/medias/banner/0.jpg') %>)');
</script>
<% } %>
  • 然后执行相关的本地预览和部署命令查看效果即可