Next主题可增加友链,在主题配置文件_config.yml
中links
下添加,比如:
links:
github: https://github.com/leafjame
daovoice: http://www.daovoice.io/
YouTube: https://youtube.com/channel/UCtzIJK9eLCWLQF13KpZE-0w
Jianshu: https://www.jianshu.com/u/3b74c7b81348
首页展示效果:
image
当链接变多以后,页面的排版很不美观,这时候就需要给友链新增一个单独的页面了。
步骤
新增links页面
在控制台使用命令创建:
$ hexo new page links
注:也可在source
目录下手动创建(还需要手动创建index.md文件)
配置menu
主题配置文件_config.yml
中menu
下添加:
links: /links/ || link
/themes/next/languages/zh-Hans.yml
文件中menu
下增加中文描述:
links: 友链
做完这些工作,接下来就是要增加友链页面的样式了
新增links.swig
页
在/themes/next/layout/
新建links.swig
,内容如下:
{% 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.mylinks %}
<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
文件,在
#}{% elif page.type === "tags" and not page.title %}{#
#}{{ __('title.tag') + page_title_suffix }}{#
位置下添加代码:
<!-- 友情链接-->
#}{% elif page.type === 'links' and not page.title %}{#
#}{{ __('title.links') + page_title_suffix }}{#
效果如下:
image
引入links.swig
接着在/themes/next/layout/page.swig
中,引入刚才新建的page.swig
:
<!-- 友情链接-->
{% elif page.type === 'links' %}
{% include 'links.swig' %}
比如我是在
{% elif page.type === 'categories' %}
这个if
下追加的:
image
到这里就完成页面样式的配置了。。。
配置友链
接下来,在/themes/next/_config.yml
文件中配置友链,末尾处新增mylinks
,如下:
mylinks:
- nickname: Fi9Coder #友链名称
avatar: https://www.safeinfo.me/images/avatar.gif #友链头像
site: https://www.safeinfo.me #友链地址
info: 致力于Web安全与Python学习,研究,开发。 #友链说明
- nickname: Leaf's Blog
avatar: https://leafjame.github.io/images/beichen.png
site: https://leafjame.github.io
info: Java狮 北漂男 摄影 旅行 赚钱
这里是配置了两个友链,多个的配置方式相同。
轻敲hexo
命令三连,看看效果吧~😜
image
参考文章:Hexo修改友链样式
还有一种比较不错的做法,可参考枫糖
的博客:Next 主题自定义友链页面。模仿Hexo NexT 博客增加瀑布流相册页面的功能实现的
相册功能参考:Hexo NexT主题内添加相册功能