hexo博客:next主题添加友链页面

效果预览:

准备工作

  • 打开/blog/themes/next/languages/zh-CN.yml文档,menu下添加中文友链
zh-CN.yml
1
2
menu:
+ links: 友链
  • 修改主题配置文件/blog/themes/next/config.yaml
config.yaml
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
# 菜单添加友链页面
menu:
home: / || home
#about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
photos: /photos/ || image
+ links: /links/ || leaf
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat

......

# 末尾友情链接
mylinks:
- nickname: XiaoXiaoTao # 昵称
avatar: https://hexo-1257031621.cos.ap-chengdu.myqcloud.com/%E5%8D%9A%E5%AE%A2%E9%85%8D%E5%9B%BE/%E5%8D%9A%E5%AE%A2%E8%83%8C%E6%99%AF%E5%A4%B4%E5%83%8F/%E5%B0%8F%E5%A5%B3%E5%AD%A9%E5%A4%B4%E5%83%8F.jpg # 头像地址
site: https://xiaoxiaotaoya.github.io/ #友链地址
info: 停止更新的老博客

- nickname: 创客智造 # 昵称
avatar: https://www.ncnynl.com/usr/themes/default/img/ckzz.png # 头像地址
site: https://www.ncnynl.com/ #友链地址
info: ROS机器人教程

- nickname: Sanarous # 昵称
avatar: https://site-1258928558.cos.ap-guangzhou.myqcloud.com/javadoop.png # 头像地址
site: https://bestzuo.cn #友链地址
info: 码农人生

- nickname: Leaf's Blog
avatar: https://www.liaofuzhan.com/images/beichen.png
site: https://www.liaofuzhan.com
info: 因心造境,风云由我!

新建友链文章和模板页面

  • 新建相册文章;修改D:/blog/source/links/index.md
$ hexo new page links
index.md
1
2
3
4
5
6
---
title: 友人帐
date: 2020-03-13 09:38:29
layout: "links"
comments: false
---
  • 创建友链模板/blog/themes/next/layout/links.swig
links.swig
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
<meta charset='utf-8'>
{% extends '_layout.swig' %}
{% import '_macro/post-collapse.swig' as post_template with context %}
{% import '_macro/sidebar.swig' as sidebar_template with context %}

{% block content %}
{######################}
{### LINKS BLOCK ###}
{######################}

<div id="links">
<div id="links">
<style>
.links-content{
margin-top:1rem;
}

.link-navigation::after {
content: " ";
display: block;
clear: both;
}

.card {
width: 35%;
font-size: 1rem;
padding: 20px 20px;
border-radius: 4px;
transition-duration: 0.15s;
margin-bottom: 1rem;
display:flex;
}

@media(max-width: 1400px){
.card{
width: 35% !important;
}
}
.card:nth-child(odd) {
float: left;
}
.card:nth-child(even) {
float: right;
}
.card:hover {
transform: scale(1.1);
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
}
.card a {
border:none;
}
.card .ava {
width: 3rem!important;
height: 3rem!important;
margin:0!important;
margin-right: 1em!important;
border-radius:4px;

}
.card .card-header {
font-style: italic;
overflow: hidden;
width: 100%;
}
.card .card-header a {
font-style: normal;
color: #2bbc8a;
font-weight: bold;
text-decoration: none;
}
.card .card-header a:hover {
color: #d480aa;
text-decoration: none;
}
.card .card-header .info {
font-style:normal;
color:#a3a3a3;
font-size:14px;
min-width: 0;
overflow: hidden;
white-space: nowrap;
}

span.focus-links {
font-style: normal;
margin-left: 10px;
position: unset;
left: 0;
padding: 0 7px 0 5px;
font-size: 11px;
border-color: #42c02e;
border-radius: 40px;
line-height: 24px;
height: 22px;
color: #fff !important;
background-color: #42c02e;
display: inline-block;
}
span.focus-links:hover{
background-color: #318024;
}

.friends-btn{
text-align: center;
color: #555!important;
background-color: #fff;
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0 0 10px 0 rgba(0,0,0,.35);
border: none!important;
transition-property: unset;
padding: 0 15px;
margin: inherit;
}

.friends-btn:hover{
color: rgb(255, 255, 255) !important;
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, 0.35);
background-image: linear-gradient(90deg, #a166ab 0%, #ef4e7b 25%, #f37055 50%, #ef4e7b 75%, #a166ab 100%);
margin: inherit;
}
}

</style>
<div class="posts-expand">
<div class="post-block" lang="{{ page.lang or page.language or config.language }}">
{% include '_partials/page/page-header.swig' %}
<div class="container">
<div class="links-content">
<div class="link-navigation">
{% for link in theme.mylinks %}
<div class="card">
<img class="ava" src="{{ link.avatar }}"/>
<div class="card-header">
<div><a href="{{ link.site }}" target="_blank"> {{ link.nickname }}</a> <a href="{{ link.site }}"><span class="focus-links">+关注</span></a></div>
<div class="info">{{ link.info }}</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{##########################}
{### END LINKS BLOCK ###}
{##########################}
{% endblock %}

{% block sidebar %}
{{ sidebar_template.render(true) }}
{% endblock %}
  • 输入命令,查看创建效果
$ hexo clean && hexo g && hexo s

参考

+