Skip to content

Commit

Permalink
Merge pull request theme-next#109 from tsanie/feature-related-posts
Browse files Browse the repository at this point in the history
Feature: related posts, according to theme-next#67
  • Loading branch information
tsanie authored Feb 9, 2018
2 parents b21435e + f4fdeb1 commit cc4290f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
13 changes: 13 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ symbols_count_time:
#alipay: /images/alipay.jpg
#bitcoin: /images/bitcoin.png

# Related popular posts
# Dependencies: https://github.com/tea3/hexo-related-popular-posts
related_posts:
enable: false
title: # custom header, leave empty to use the default one
display_in_home: false
params:
maxCount: 5
#PPMixingRate: 0.0
#isDate: false
#isImage: false
#isExcerpt: false

# Declare license on posts
post_copyright:
enable: false
Expand Down
1 change: 1 addition & 0 deletions languages/_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ post:
symbols_time: Reading time
total_symbols: Symbols count total
total_time: Reading time total
related_posts: Related Posts
copyright:
author: Post author
link: Post link
Expand Down
20 changes: 20 additions & 0 deletions layout/_macro/post-related.swig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% set popular_posts = popular_posts_json(theme.related_posts.params, post) %}
{% if popular_posts.json and popular_posts.json.length > 0 %}
<div class="popular-posts-header">{{ theme.related_posts.title | default(__('post.related_posts')) }}</div>
<ul class="popular-posts">
{% for popular_post in popular_posts.json %}
<li class="popular-posts-item">
{% if popular_post.date and popular_post.date != '' %}
<div class="popular-posts-date">{{ popular_post.date }}</div>
{% endif %}
{% if popular_post.img && popular_post.img != '' %}
<div class="popular-posts-img"><img src="{{ popular_post.img }}" /></div>
{% endif %}
<div class="popular-posts-title"><a href="{{ popular_post.path }}" rel="bookmark">{{ popular_post.title }}</a></div>
{% if popular_post.excerpt && popular_post.excerpt != '' %}
<div class="popular-posts-excerpt"><p>{{ popular_post.excerpt }}</p></div>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
5 changes: 5 additions & 0 deletions layout/_macro/post.swig
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@
{{ post.content }}
{% endif %}
</div>

{% if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %}
{% include 'post-related.swig' with { post: post } %}
{% endif %}

{#####################}
{### END POST BODY ###}
{#####################}
Expand Down
22 changes: 22 additions & 0 deletions source/css/_common/components/third-party/related-posts.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.popular-posts-header {
margin-top: $post-eof-margin-bottom;
margin-bottom: 10px;
font-size: $font-size-headings-base;
border-bottom: 1px solid $gainsboro;
display: block;
}

ul.popular-posts {
padding: 0;

.popular-posts-item {
// list-style: none;
margin-left: 2em;
.popular-posts-title {
font-weight: normal;
font-size: $font-size-base;
margin: 0;
line-height: $line-height-base * 1.2;
}
}
}
1 change: 1 addition & 0 deletions source/css/_common/components/third-party/third-party.styl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@import "busuanzi-counter";
@import "algolia-search" if hexo-config('algolia_search.enable');
@import "needsharebutton" if hexo-config('needmoreshare2.enable');
@import "related-posts" if hexo-config('related_posts.enable');

0 comments on commit cc4290f

Please sign in to comment.