0%

添加友链踩坑记录

新增links页面

1
$ hexo new page links

配置menu

主题配置文件_config.ymlmenu下添加:

1
links: /links/ || fa fa-link

/themes/next/languages/zh-Hans.yml文件中menu下增加中文描述:

1
links: 友链

做完这些工作,接下来就是要增加友链页面的样式了

/themes/next/layout/新建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
{% block content %}
{######################}
{### LINKS BLOCK ###}
{######################}

<div id="links">
<style>

#links{
margin-top: 5rem;
}

.links-content{
margin-top:1rem;
}

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

.card {
width: 300px;
font-size: 1rem;
padding: 10px 20px;
border-radius: 4px;
transition-duration: 0.15s;
margin-bottom: 1rem;
display:flex;
}
.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: 236px;
}
.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;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
</style>
<div class="links-content">
<div class="link-navigation">

{% for link in theme.friendlinks %}

<div class="card">
<img class="ava" src="{{ link.avatar }}"/>
<div class="card-header">
<div><a href="{{ link.site }}" target="_blank">@ {{ link.nickname }}</a></div>
<div class="info">{{ link.info }}</div>
</div>
</div>

{% endfor %}

</div>
{{ page.content }}
</div>
</div>

{##########################}
{### END LINKS BLOCK ###}
{##########################}
{% endblock %}

修改page.swig

修改/themes/next/layout/page.swig文件,在

1
2
{%- elif page.type === 'schedule' and not page.title %}
{{- __('title.schedule') + page_title_suffix }}

下面添加:

1
2
{%- elif page.type === 'links' and not page.title %}
{{- __('title.links') + page_title_suffix }}

关键在于所有的教程中给了引入代码,但没有说具体在哪里插入

/themes/next/layout/page.swig中的

1
2
3
4
5
{% elif page.type === 'schedule' %}
<div class="event-list">
</div>

{% include '_scripts/pages/schedule.swig' %}

插入

1
2
{% elif page.type === 'links' %}
{% include 'links.swig' %}

得到

1
2
3
4
5
6
{% elif page.type === 'schedule' %}
<div class="event-list">
</div>
{% elif page.type === 'links' %}
{% include 'links.swig' %}
{% include '_scripts/pages/schedule.swig' %}

主题配置添加

在主题配置文件_config.yml末尾处添加友链:

1
2
3
4
5
6
7
8
9
mylinks:
- nickname: #友链名称
avatar: #友链头像
site: #友链地址
info: #友链说明
- nickname: #友链名称
avatar: #友链头像
site: #友链地址
info: #友链说明
技术分享,如果您觉得内容不错的话不妨进行打赏,您的支持将鼓励我继续创作!


如果你对本文有看法或更好的见解可以点击下方按钮进行评论
*注:本站为非交互网站
此按钮将会转跳至评论站点 i-nmb.chat 进行评论

欢迎关注我的其它发布渠道