From 0d4103d47bc9cff93918bb09a2957737cc3c9fe0 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Tue, 8 Aug 2023 06:47:36 +0800 Subject: [PATCH] perf(core): speed up the Jekyll build times (#1163) Refactor `_includes/related-posts.html` --- _includes/related-posts.html | 47 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/_includes/related-posts.html b/_includes/related-posts.html index 8476a6d..e1876be 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -1,7 +1,4 @@ - + {% assign TOTAL_SIZE = 3 %} @@ -14,11 +11,21 @@ {% 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: '' %} -{% assign last_index = site.posts.size | minus: 1 %} {% for i in (0..last_index) %} - {% assign post = site.posts[i] %} + {% assign post = match_posts[i] %} {% if post.url == page.url %} {% continue %} @@ -54,34 +61,20 @@ {% endfor %} {% endif %} - -{% assign less = TOTAL_SIZE | minus: index_list.size %} +{% assign relate_posts = '' | split: '' %} -{% if less > 0 %} - {% for i in (0..last_index) %} - {% assign post = site.posts[i] %} - {% if post.url != page.url %} - {% capture cur_index %}{{ i }}{% endcapture %} - {% unless index_list contains cur_index %} - {% assign index_list = index_list | push: cur_index %} - {% assign less = less | minus: 1 %} - {% if less <= 0 %} - {% break %} - {% endif %} - {% endunless %} - {% endif %} - {% endfor %} -{% endif %} +{% for index in index_list %} + {% assign i = index | to_integer %} + {% assign relate_posts = relate_posts | push: match_posts[i] %} +{% endfor %} -{% if index_list.size > 0 %} +{% if relate_posts.size > 0 %}