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

Speed up the Jekyll build times for large sites #1163

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
51 changes: 23 additions & 28 deletions _includes/related-posts.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<!--
Recommend the other 3 posts according to the tags and categories of the current post,
if the number is not enough, use the other latest posts to supplement.
-->
<!-- Recommend the other 3 posts according to the tags and categories of the current post. -->

<!-- The total size of related posts -->
{% assign TOTAL_SIZE = 3 %}
Expand All @@ -14,11 +11,23 @@

{% assign SEPARATOR = ':' %}

{% assign match_posts = '' | split: '' %}

{% for category in page.categories %}
{% assign temp = site.posts | where_exp: 'item', 'item.categories contains category' %}
{% assign match_posts = match_posts | push: temp %}
{% endfor %}

{% for tag in page.tags %}
{% assign temp = site.posts | where_exp: 'item', 'item.categories contains tag' %}
{% assign match_posts = match_posts | push: temp %}
{% 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 %}
Expand Down Expand Up @@ -54,34 +63,20 @@
{% endfor %}
{% endif %}

<!-- Fill with the other newlest posts -->
{% assign less = TOTAL_SIZE | minus: index_list.size %}

{% 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 %}
{% 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 index_list.size > 0 %}
{% if relate_posts.size > 0 %}
<div id="related-posts" class="mb-2 mb-sm-4">
<h3 class="pt-2 mb-4 ms-1" data-toc-skip>
{{ site.data.locales[include.lang].post.relate_posts }}
</h3>
<div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 g-4 mb-4">
{% for entry in index_list %}
{% assign index = entry | plus: 0 %}
{% assign post = site.posts[index] %}
{% for post in relate_posts %}
<div class="col">
<a href="{{ post.url | relative_url }}" class="card post-preview h-100">
<div class="card-body">
Expand Down