文章最新图标
文章最新图标
左.步骤
- 在
...themes\butterfly\scripts\helpers\page.js
文件下添加如下代码1
2
3
4
5
6
7
8
9// 最新文章
hexo.extend.helper.register('newPost', function() {
let name, time;
hexo.locals.get('posts').map((item, index) => {
if (index == 0) name = item.title, time = item.date
else if (item.date > time) { name = item.title, time = item.date }
});
return name
}) - 在
..\themes\butterfly\layout\includes\mixins\post-ui.pug
添加1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19mixin postUI(posts)
+ - let newTitle= newPost()
each article , index in page.posts.data
·
·
·
if post_cover && theme.cover.index_enable
.post_cover(class=leftOrRight)
a(href=url_for(link) title=title)
if article.cover_type === 'img'
img.post-bg(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
else
div.post-bg(style=`background: ${post_cover}`)
+ .recent-post-info(class=no_cover)
+ if newTitle == title
+ span(class=`newPost-${leftOrRight=='left'?'right':'left'}`) 最新
a.article-title(href=url_for(link) title=title)= title - 最后在自定义的css文件中添加如下代码,并在主题中引入最后一键三连即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#recent-posts>.recent-post-item {
position: relative;
}
/* 最新文章图标 */
.newPost-left,
.newPost-right {
position: absolute;
top: 0;
color: white;
padding: 0 15px;
background-color: #49b1f5;
border-radius: 0 0 10px 10px;
}
.newPost-left {
left: 15px;
}
.newPost-right {
right: 15px;
}
评论
匿名评论隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果