Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: related posts, according to #67 #109

Merged
merged 8 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

Copy link
Member

@ivan-nginx ivan-nginx Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many for now. oO Mb move to external swig file?
Like post-copyright.swig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivan-nginx OK, seems now it need to be move to the single file.

{% 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');