From c9a515bbb152aa80fa76e93669ac22eb784938df Mon Sep 17 00:00:00 2001 From: Adarsh D Date: Sun, 19 Nov 2023 22:25:02 +0530 Subject: [PATCH] change: move subscription box to related post section --- _includes/comments.html | 82 ---------------- _includes/related-posts.html | 180 +++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 82 deletions(-) create mode 100644 _includes/related-posts.html diff --git a/_includes/comments.html b/_includes/comments.html index 018a947..362aa92 100644 --- a/_includes/comments.html +++ b/_includes/comments.html @@ -1,85 +1,3 @@ - - - - -
-
- Subscribe to get new posts like this by email -
- -

- {% if page.comments and site.comments.active %} {% capture path %}comments/{{ site.comments.active }}.html{% endcapture %} diff --git a/_includes/related-posts.html b/_includes/related-posts.html new file mode 100644 index 0000000..41800ea --- /dev/null +++ b/_includes/related-posts.html @@ -0,0 +1,180 @@ + + + + +
+
+ Subscribe to get new posts like this by email +
+ +

+ + + + + +{% assign TOTAL_SIZE = 3 %} + + +{% assign TAG_SCORE = 1 %} + + +{% assign CATEGORY_SCORE = 0.5 %} + +{% assign SEPARATOR = ':' %} + +{% assign match_posts = '' | split: '' %} + +{% for category in page.categories %} +{% assign match_posts = match_posts | push: site.categories[category] | uniq %} +{% endfor %} + +{% for tag in page.tags %} +{% assign match_posts = match_posts | push: site.tags[tag] | uniq %} +{% endfor %} + +{% assign last_index = match_posts.size | minus: 1 %} +{% assign score_list = '' | split: '' %} + +{% for i in (0..last_index) %} +{% assign post = match_posts[i] %} + +{% if post.url == page.url %} +{% continue %} +{% endif %} + +{% assign score = 0 %} + +{% for tag in post.tags %} +{% if page.tags contains tag %} +{% assign score = score | plus: TAG_SCORE %} +{% endif %} +{% endfor %} + +{% for category in post.categories %} +{% if page.categories contains category %} +{% assign score = score | plus: CATEGORY_SCORE %} +{% endif %} +{% endfor %} + +{% if score > 0 %} +{% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %} +{% assign score_list = score_list | push: score_item %} +{% endif %} +{% endfor %} + +{% assign index_list = '' | split: '' %} + +{% if score_list.size > 0 %} +{% assign score_list = score_list | sort | reverse %} +{% for entry in score_list limit: TOTAL_SIZE %} +{% assign index = entry | split: SEPARATOR | last %} +{% assign index_list = index_list | push: index %} +{% endfor %} +{% endif %} + +{% assign relate_posts = '' | split: '' %} + +{% for index in index_list %} +{% assign i = index | to_integer %} +{% assign relate_posts = relate_posts | push: match_posts[i] %} +{% endfor %} + +{% if relate_posts.size > 0 %} + + +{% endif %}