hexo+github建站之近期文章

增加近期文章显示,直接修改主题sidebar.swig文件即可。

sidebar文件

layout/_macro/sidebar.swig文件if theme.links前加入以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{% if theme.recent_posts %}
<div class="links-of-blogroll motion-element {{ "links-of-blogroll-" + theme.recent_posts_layout }}">
<div class="links-of-blogroll-title">
<!-- modify icon to fire by szw -->
<i class="fa fa-history fa-{{ theme.recent_posts_icon | lower }}" aria-hidden="true"></i>
{{ theme.recent_posts_title }}
</div>
<ul class="links-of-blogroll-list">
{% set posts = site.posts.sort('-date') %}
{% for post in posts.slice('0', '5') %}
<li>
<a href="{{ url_for(post.path) }}" title="{{ post.title }}" target="_blank">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
/div>
{% endif %}

主题配置

在主题配置文件 _config.yml 中新增3个变量

1
2
3
recent_posts: true
recent_posts_title: 近期文章
recent_posts_layout: block

效果验证

1
# hexo clean; hexo g; hexo s