1. Fixed: display related posts headline when it is not related posts

2. Fixed: the bugs of image display
This commit is contained in:
hwy0127@gmail.com
2019-07-27 01:59:59 +08:00
parent f07405706b
commit 6c59f72ca2
9 changed files with 51 additions and 45 deletions

View File

@@ -51,7 +51,6 @@ pagination:
next: Next Post
comment: Comment
relatedPosts_headline: Recommend
aside:
articles: Articles

View File

@@ -51,7 +51,6 @@ pagination:
next: Next Post
comment: Comment
relatedPosts_headline: Recommend
aside:
articles: Articles

View File

@@ -52,7 +52,6 @@ pagination:
next: 下一篇
comment: 评论
relatedPosts_headline: 相关推荐
aside:
articles: 文章

View File

@@ -53,7 +53,6 @@ pagination:
next: 下一篇
comment: 評論
relatedPosts_headline: 相關推薦
aside:
articles: 文章

View File

@@ -3,7 +3,6 @@ if theme.disqus.enable
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
=" "
span= _p('comment')
include ./disqus.pug
else if theme.laibili && theme.laibili.enable
@@ -11,7 +10,6 @@ else if theme.laibili && theme.laibili.enable
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
=" "
span= _p('comment')
include ./laibili.pug
else if theme.gitment && theme.gitment.enable
@@ -19,7 +17,6 @@ else if theme.gitment && theme.gitment.enable
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
=" "
span= _p('comment')
include ./gitment.pug
else if theme.gitalk && theme.gitalk.enable
@@ -27,7 +24,6 @@ else if theme.gitalk && theme.gitalk.enable
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
=" "
span= _p('comment')
include ./gitalk.pug
else if theme.valine && theme.valine.enable
@@ -35,6 +31,5 @@ else if theme.valine && theme.valine.enable
#post-comment
.comment_headling
i.fa.fa-comments.fa-fw(aria-hidden="true")
=" "
span= _p('comment')
include ./valine.pug

View File

@@ -3,25 +3,25 @@ each article , index in page.posts.data
- var link = article.link || article.path
if index%2 == 0
.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 default_post_cover = random_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
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
.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 default_post_cover = random_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
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
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)
span.article-meta
i.fa.fa-thumb-tack.article-meta__icon.sticky

View File

@@ -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

View File

@@ -71,6 +71,6 @@ block content
include includes/pagination.pug
if theme.related_post && theme.related_post.enable
include includes/related-posts.pug
!= related_posts(page,site.posts)
if page.comments !== false
include includes/comments/index.pug

View File

@@ -1,38 +1,59 @@
hexo.extend.helper.register('related_posts', function(currentPost, allPosts){
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
var relatedPosts = [];
currentPost.tags.forEach(function (tag) {
allPosts.forEach(function (post) {
if (isTagRelated(tag.name, post.tags)) {
var relatedPost = {
title: post.title,
path: post.path,
cover: post.cover,
weight: 1
};
var index = findItem(relatedPosts, 'path', post.path);
if (index != -1) {
relatedPosts[index].weight += 1;
} else{
if (currentPost.path != post.path) {
relatedPosts.push(relatedPost);
};
};
if (isTagRelated(tag.name, post.tags)) {
var relatedPost = {
title: post.title,
path: post.path,
cover: post.cover,
weight: 1
};
var index = findItem(relatedPosts, 'path', post.path);
if (index != -1) {
relatedPosts[index].weight += 1;
} else {
if (currentPost.path != post.path) {
relatedPosts.push(relatedPost);
};
});
};
};
});
});
if (relatedPosts.length == 0) {return ''};
if (relatedPosts.length == 0) { return '' };
var result = "";
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'));
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++) {
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 +'">';
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 += '<img class="relatedPosts_cover lozad" data-src="' + cover + '">';
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;
}
});
hexo.extend.helper.register('echo', function(path){
return path;