mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
1. Fixed: display related posts headline when it is not related posts
2. Fixed: the bugs of image display
This commit is contained in:
@@ -51,7 +51,6 @@ pagination:
|
|||||||
next: Next Post
|
next: Next Post
|
||||||
|
|
||||||
comment: Comment
|
comment: Comment
|
||||||
relatedPosts_headline: Recommend
|
|
||||||
|
|
||||||
aside:
|
aside:
|
||||||
articles: Articles
|
articles: Articles
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ pagination:
|
|||||||
next: Next Post
|
next: Next Post
|
||||||
|
|
||||||
comment: Comment
|
comment: Comment
|
||||||
relatedPosts_headline: Recommend
|
|
||||||
|
|
||||||
aside:
|
aside:
|
||||||
articles: Articles
|
articles: Articles
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ pagination:
|
|||||||
next: 下一篇
|
next: 下一篇
|
||||||
|
|
||||||
comment: 评论
|
comment: 评论
|
||||||
relatedPosts_headline: 相关推荐
|
|
||||||
|
|
||||||
aside:
|
aside:
|
||||||
articles: 文章
|
articles: 文章
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ pagination:
|
|||||||
next: 下一篇
|
next: 下一篇
|
||||||
|
|
||||||
comment: 評論
|
comment: 評論
|
||||||
relatedPosts_headline: 相關推薦
|
|
||||||
|
|
||||||
aside:
|
aside:
|
||||||
articles: 文章
|
articles: 文章
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ if theme.disqus.enable
|
|||||||
#post-comment
|
#post-comment
|
||||||
.comment_headling
|
.comment_headling
|
||||||
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
||||||
=" "
|
|
||||||
span= _p('comment')
|
span= _p('comment')
|
||||||
include ./disqus.pug
|
include ./disqus.pug
|
||||||
else if theme.laibili && theme.laibili.enable
|
else if theme.laibili && theme.laibili.enable
|
||||||
@@ -11,7 +10,6 @@ else if theme.laibili && theme.laibili.enable
|
|||||||
#post-comment
|
#post-comment
|
||||||
.comment_headling
|
.comment_headling
|
||||||
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
||||||
=" "
|
|
||||||
span= _p('comment')
|
span= _p('comment')
|
||||||
include ./laibili.pug
|
include ./laibili.pug
|
||||||
else if theme.gitment && theme.gitment.enable
|
else if theme.gitment && theme.gitment.enable
|
||||||
@@ -19,7 +17,6 @@ else if theme.gitment && theme.gitment.enable
|
|||||||
#post-comment
|
#post-comment
|
||||||
.comment_headling
|
.comment_headling
|
||||||
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
||||||
=" "
|
|
||||||
span= _p('comment')
|
span= _p('comment')
|
||||||
include ./gitment.pug
|
include ./gitment.pug
|
||||||
else if theme.gitalk && theme.gitalk.enable
|
else if theme.gitalk && theme.gitalk.enable
|
||||||
@@ -27,7 +24,6 @@ else if theme.gitalk && theme.gitalk.enable
|
|||||||
#post-comment
|
#post-comment
|
||||||
.comment_headling
|
.comment_headling
|
||||||
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
||||||
=" "
|
|
||||||
span= _p('comment')
|
span= _p('comment')
|
||||||
include ./gitalk.pug
|
include ./gitalk.pug
|
||||||
else if theme.valine && theme.valine.enable
|
else if theme.valine && theme.valine.enable
|
||||||
@@ -35,6 +31,5 @@ else if theme.valine && theme.valine.enable
|
|||||||
#post-comment
|
#post-comment
|
||||||
.comment_headling
|
.comment_headling
|
||||||
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
i.fa.fa-comments.fa-fw(aria-hidden="true")
|
||||||
=" "
|
|
||||||
span= _p('comment')
|
span= _p('comment')
|
||||||
include ./valine.pug
|
include ./valine.pug
|
||||||
@@ -3,25 +3,25 @@ each article , index in page.posts.data
|
|||||||
- var link = article.link || article.path
|
- var link = article.link || article.path
|
||||||
if index%2 == 0
|
if index%2 == 0
|
||||||
.post_cover.is_left
|
.post_cover.is_left
|
||||||
a(href=url_for(link))
|
a(href=url_for(link) title=article.title || _p('no_title'))
|
||||||
- var post_cover = article.cover
|
- var post_cover = article.cover
|
||||||
- var default_post_cover = random_cover()
|
- var default_post_cover = random_cover()
|
||||||
if (post_cover)
|
if (post_cover)
|
||||||
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
|
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
|
||||||
else
|
else
|
||||||
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
|
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
|
||||||
else
|
else
|
||||||
.post_cover.is_right
|
.post_cover.is_right
|
||||||
a(href=url_for(link))
|
a(href=url_for(link) title=article.title || _p('no_title'))
|
||||||
- var post_cover = article.cover
|
- var post_cover = article.cover
|
||||||
- var default_post_cover = random_cover()
|
- var default_post_cover = random_cover()
|
||||||
if (post_cover)
|
if (post_cover)
|
||||||
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
|
img.post_bg.lozad(data-src=`${post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
|
||||||
else
|
else
|
||||||
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'` title=article.title || _p('no_title'))
|
img.post_bg.lozad(data-src=`${default_post_cover}` onerror=`onerror=null;src='${theme.lodding_bg.post_page}'`)
|
||||||
|
|
||||||
.recent-post-info
|
.recent-post-info
|
||||||
a.article-title(href=url_for(link) title=article.title || _p('no_title'))= article.title || _p('no_title')
|
a.article-title(href=url_for(link) title= article.title || _p('no_title'))= article.title || _p('no_title')
|
||||||
if (article.top)
|
if (article.top)
|
||||||
span.article-meta
|
span.article-meta
|
||||||
i.fa.fa-thumb-tack.article-meta__icon.sticky
|
i.fa.fa-thumb-tack.article-meta__icon.sticky
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
.relatedPosts
|
|
||||||
.relatedPosts_headline
|
|
||||||
i.fa.fa-thumbs-up(aria-hidden="true")
|
|
||||||
span=' ' + _p('relatedPosts_headline')
|
|
||||||
.relatedPosts_list!= related_posts(page,site.posts)
|
|
||||||
.clear_both
|
|
||||||
@@ -71,6 +71,6 @@ block content
|
|||||||
include includes/pagination.pug
|
include includes/pagination.pug
|
||||||
|
|
||||||
if theme.related_post && theme.related_post.enable
|
if theme.related_post && theme.related_post.enable
|
||||||
include includes/related-posts.pug
|
!= related_posts(page,site.posts)
|
||||||
if page.comments !== false
|
if page.comments !== false
|
||||||
include includes/comments/index.pug
|
include includes/comments/index.pug
|
||||||
@@ -1,38 +1,59 @@
|
|||||||
hexo.extend.helper.register('related_posts', function(currentPost, allPosts){
|
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||||
var relatedPosts = [];
|
var relatedPosts = [];
|
||||||
currentPost.tags.forEach(function (tag) {
|
currentPost.tags.forEach(function (tag) {
|
||||||
allPosts.forEach(function (post) {
|
allPosts.forEach(function (post) {
|
||||||
if (isTagRelated(tag.name, post.tags)) {
|
if (isTagRelated(tag.name, post.tags)) {
|
||||||
var relatedPost = {
|
var relatedPost = {
|
||||||
title: post.title,
|
title: post.title,
|
||||||
path: post.path,
|
path: post.path,
|
||||||
cover: post.cover,
|
cover: post.cover,
|
||||||
weight: 1
|
weight: 1
|
||||||
};
|
};
|
||||||
var index = findItem(relatedPosts, 'path', post.path);
|
var index = findItem(relatedPosts, 'path', post.path);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
relatedPosts[index].weight += 1;
|
relatedPosts[index].weight += 1;
|
||||||
} else{
|
} else {
|
||||||
if (currentPost.path != post.path) {
|
if (currentPost.path != post.path) {
|
||||||
relatedPosts.push(relatedPost);
|
relatedPosts.push(relatedPost);
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
if (relatedPosts.length == 0) {return ''};
|
if (relatedPosts.length == 0) { return '' };
|
||||||
var result = "";
|
var result = "";
|
||||||
var limit_num = hexo.theme.config.related_post.limit || 6
|
var limit_num = hexo.theme.config.related_post.limit || 6
|
||||||
|
var lang = hexo.theme.config.rootConfig.language;
|
||||||
|
var headline_lang;
|
||||||
|
if (lang === 'zh-CN') {
|
||||||
|
headline_lang = '相关推荐';
|
||||||
|
} else if ( lang === 'zh-TW') {
|
||||||
|
headline_lang = '相關推薦';
|
||||||
|
} else {
|
||||||
|
headline_lang = 'Recommend';
|
||||||
|
}
|
||||||
|
|
||||||
relatedPosts = relatedPosts.sort(compare('weight'));
|
relatedPosts = relatedPosts.sort(compare('weight'));
|
||||||
|
|
||||||
|
if (relatedPosts.length > 0) {
|
||||||
|
result += '<div class="relatedPosts">'
|
||||||
|
result += '<div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span>' + headline_lang + '</span></div>'
|
||||||
|
result += '<div class="relatedPosts_list">'
|
||||||
|
|
||||||
for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) {
|
for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) {
|
||||||
|
|
||||||
var cover = relatedPosts[i].cover|| random_cover()
|
var cover = relatedPosts[i].cover || random_cover()
|
||||||
result += '<div class="relatedPosts_item"><a href="' + hexo.theme.config.rootConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title +'">';
|
|
||||||
|
result += '<div class="relatedPosts_item"><a href="' + hexo.theme.config.rootConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">';
|
||||||
result += '<img class="relatedPosts_cover lozad" data-src="' + cover + '">';
|
result += '<img class="relatedPosts_cover lozad" data-src="' + cover + '">';
|
||||||
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
|
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
|
||||||
result += '</a></div>'
|
result += '</a></div>'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
result += '</div><div class="clear_both"></div></div>'
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
hexo.extend.helper.register('echo', function(path){
|
hexo.extend.helper.register('echo', function(path){
|
||||||
return path;
|
return path;
|
||||||
|
|||||||
Reference in New Issue
Block a user