From ee806287b1c48452bd3ad2f3d90d4418352e21d4 Mon Sep 17 00:00:00 2001 From: tsanie Date: Tue, 30 Jan 2018 20:45:13 +0800 Subject: [PATCH 1/7] initial related-posts --- _config.yml | 12 ++++++++++++ layout/_macro/post.swig | 5 +++++ .../components/third-party/related-posts.styl | 19 +++++++++++++++++++ .../components/third-party/third-party.styl | 1 + 4 files changed, 37 insertions(+) create mode 100644 source/css/_common/components/third-party/related-posts.styl diff --git a/_config.yml b/_config.yml index d77ee2c6c1..06077aa42b 100644 --- a/_config.yml +++ b/_config.yml @@ -280,6 +280,18 @@ 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: true + params: + maxCount: 5 + #ulClass: 'popular-posts' + PPMixingRate: 1.0 + #isDate: false + #isImage: false + #isExcerpt: false + # Declare license on posts post_copyright: enable: false diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index 7fa623390f..cb41bf4739 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -332,6 +332,11 @@ {{ post.content }} {% endif %} + + {% if theme.related_posts.enable %} + {{ popular_posts(theme.related_posts.params, post) }} + {% endif %} + {#####################} {### END POST BODY ###} {#####################} diff --git a/source/css/_common/components/third-party/related-posts.styl b/source/css/_common/components/third-party/related-posts.styl new file mode 100644 index 0000000000..cb4303cfcb --- /dev/null +++ b/source/css/_common/components/third-party/related-posts.styl @@ -0,0 +1,19 @@ +ul.popular-posts { + padding: 0; + + .popular-posts-item { + list-style: none; + + .popular-posts-title { + display: block; + + h3 { + font-weight: normal; + + a { + text-decoration: none; + } + } + } + } +} \ No newline at end of file diff --git a/source/css/_common/components/third-party/third-party.styl b/source/css/_common/components/third-party/third-party.styl index 488b6e7b0f..0896976b1a 100644 --- a/source/css/_common/components/third-party/third-party.styl +++ b/source/css/_common/components/third-party/third-party.styl @@ -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'); From 3d88bbb52aa63ff14d6c17a257631dd2246819e2 Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 2 Feb 2018 20:43:58 +0800 Subject: [PATCH 2/7] style adjust --- _config.yml | 1 + .../components/third-party/related-posts.styl | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/_config.yml b/_config.yml index 06077aa42b..12139b74a2 100644 --- a/_config.yml +++ b/_config.yml @@ -284,6 +284,7 @@ symbols_count_time: # Dependencies: https://github.com/tea3/hexo-related-popular-posts related_posts: enable: true + title: params: maxCount: 5 #ulClass: 'popular-posts' diff --git a/source/css/_common/components/third-party/related-posts.styl b/source/css/_common/components/third-party/related-posts.styl index cb4303cfcb..e61e06974d 100644 --- a/source/css/_common/components/third-party/related-posts.styl +++ b/source/css/_common/components/third-party/related-posts.styl @@ -1,18 +1,25 @@ ul.popular-posts { padding: 0; - .popular-posts-item { - list-style: none; + &:before { + content: hexo-config('related_posts.title') || 'Related Posts'; + margin-top: $post-eof-margin-bottom; + margin-bottom: 10px; + font-size: $font-size-headings-base; + border-bottom: 1px solid $gainsboro; + display: block; + } + .popular-posts-item { + // list-style: none; + margin-left: 2em; .popular-posts-title { display: block; - h3 { font-weight: normal; - - a { - text-decoration: none; - } + font-size: $font-size-base; + margin: 0; + line-height: $line-height-base * 1.2; } } } From a6a5968636f9caa32b9bd567ca4819ab3ca68271 Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 2 Feb 2018 21:45:17 +0800 Subject: [PATCH 3/7] set the default configure --- _config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_config.yml b/_config.yml index 12139b74a2..44cf990b21 100644 --- a/_config.yml +++ b/_config.yml @@ -283,12 +283,12 @@ symbols_count_time: # Related popular posts # Dependencies: https://github.com/tea3/hexo-related-popular-posts related_posts: - enable: true + enable: false title: params: maxCount: 5 #ulClass: 'popular-posts' - PPMixingRate: 1.0 + #PPMixingRate: 0.0 #isDate: false #isImage: false #isExcerpt: false From e4117a44828e7e5cd565dd0ee2de448ca92f3fde Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 9 Feb 2018 11:10:17 +0800 Subject: [PATCH 4/7] add a switch to determine whether related posts will be shown in the home page, and add support to i18n. --- _config.yml | 3 +-- languages/_en.yml | 1 + layout/_macro/post.swig | 6 ++++-- .../components/third-party/related-posts.styl | 17 ++++++++--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/_config.yml b/_config.yml index 198cf2ee2e..62e8c5e650 100644 --- a/_config.yml +++ b/_config.yml @@ -284,10 +284,9 @@ symbols_count_time: # Dependencies: https://github.com/tea3/hexo-related-popular-posts related_posts: enable: false - title: + display_in_home: false params: maxCount: 5 - #ulClass: 'popular-posts' #PPMixingRate: 0.0 #isDate: false #isImage: false diff --git a/languages/_en.yml b/languages/_en.yml index 2579e5e7e3..b9a027a197 100644 --- a/languages/_en.yml +++ b/languages/_en.yml @@ -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 diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index cb41bf4739..6b6ff7ec42 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -333,8 +333,10 @@ {% endif %} - {% if theme.related_posts.enable %} - {{ popular_posts(theme.related_posts.params, post) }} + {% if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %} + {% set popular_html = popular_posts(theme.related_posts.params, post) %} + {% if popular_html != '' %}{% endif %} + {{ popular_html }} {% endif %} {#####################} diff --git a/source/css/_common/components/third-party/related-posts.styl b/source/css/_common/components/third-party/related-posts.styl index e61e06974d..906ebb66df 100644 --- a/source/css/_common/components/third-party/related-posts.styl +++ b/source/css/_common/components/third-party/related-posts.styl @@ -1,15 +1,14 @@ +.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; - &:before { - content: hexo-config('related_posts.title') || 'Related Posts'; - margin-top: $post-eof-margin-bottom; - margin-bottom: 10px; - font-size: $font-size-headings-base; - border-bottom: 1px solid $gainsboro; - display: block; - } - .popular-posts-item { // list-style: none; margin-left: 2em; From 9298256a418241094b364cd505698c9981813070 Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 9 Feb 2018 13:06:49 +0800 Subject: [PATCH 5/7] using the custom output template. --- _config.yml | 1 + layout/_macro/post.swig | 23 ++++++++++++++++--- .../components/third-party/related-posts.styl | 11 ++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/_config.yml b/_config.yml index 62e8c5e650..9759f39519 100644 --- a/_config.yml +++ b/_config.yml @@ -284,6 +284,7 @@ symbols_count_time: # Dependencies: https://github.com/tea3/hexo-related-popular-posts related_posts: enable: false + title: Test # custom header, leave empty to use the default one display_in_home: false params: maxCount: 5 diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index 6b6ff7ec42..e0bce4dd45 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -334,9 +334,26 @@ {% if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %} - {% set popular_html = popular_posts(theme.related_posts.params, post) %} - {% if popular_html != '' %}{% endif %} - {{ popular_html }} + {% set popular_posts = popular_posts_json(theme.related_posts.params, post) %} + {% if popular_posts.json and popular_posts.json.length > 0 %} + + + {% endif %} {% endif %} {#####################} diff --git a/source/css/_common/components/third-party/related-posts.styl b/source/css/_common/components/third-party/related-posts.styl index 906ebb66df..7c1e6c4bd0 100644 --- a/source/css/_common/components/third-party/related-posts.styl +++ b/source/css/_common/components/third-party/related-posts.styl @@ -13,13 +13,10 @@ ul.popular-posts { // list-style: none; margin-left: 2em; .popular-posts-title { - display: block; - h3 { - font-weight: normal; - font-size: $font-size-base; - margin: 0; - line-height: $line-height-base * 1.2; - } + font-weight: normal; + font-size: $font-size-base; + margin: 0; + line-height: $line-height-base * 1.2; } } } \ No newline at end of file From 3a6f571ff4ba502bb083b3840a3bbc6ab9724034 Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 9 Feb 2018 13:09:34 +0800 Subject: [PATCH 6/7] fix the default configure --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 9759f39519..38d7a502e8 100644 --- a/_config.yml +++ b/_config.yml @@ -284,7 +284,7 @@ symbols_count_time: # Dependencies: https://github.com/tea3/hexo-related-popular-posts related_posts: enable: false - title: Test # custom header, leave empty to use the default one + title: # custom header, leave empty to use the default one display_in_home: false params: maxCount: 5 From f4fdeb1ecfc14b1e7f65702131ee60921ff73ecc Mon Sep 17 00:00:00 2001 From: tsanie Date: Fri, 9 Feb 2018 13:37:56 +0800 Subject: [PATCH 7/7] move the template to the single file. --- layout/_macro/post-related.swig | 20 ++++++++++++++++++++ layout/_macro/post.swig | 21 +-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 layout/_macro/post-related.swig diff --git a/layout/_macro/post-related.swig b/layout/_macro/post-related.swig new file mode 100644 index 0000000000..2853b45acf --- /dev/null +++ b/layout/_macro/post-related.swig @@ -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 %} + + +{% endif %} diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index e0bce4dd45..abc5ca8704 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -334,26 +334,7 @@ {% if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %} - {% set popular_posts = popular_posts_json(theme.related_posts.params, post) %} - {% if popular_posts.json and popular_posts.json.length > 0 %} - - - {% endif %} + {% include 'post-related.swig' with { post: post } %} {% endif %} {#####################}