|
1 | 1 | <!--
|
2 |
| - Recommend the other 3 posts according to the tags and categories of the current post, |
3 |
| - if the number is not enough, use the other latest posts to supplement. |
| 2 | + Recommend the other 3 posts according to the tags and categories of the current post, |
| 3 | + if the number is not enough, use the other latest posts to supplement. |
4 | 4 | -->
|
5 | 5 |
|
6 |
| -<!-- The total size of related posts --> |
| 6 | +<!-- The total size of related posts --> |
7 | 7 | {% assign TOTAL_SIZE = 3 %}
|
8 | 8 |
|
9 |
| -<!-- An random integer that bigger than 0 --> |
| 9 | +<!-- An random integer that bigger than 0 --> |
10 | 10 | {% assign TAG_SCORE = 1 %}
|
11 | 11 |
|
12 |
| -<!-- Equals to TAG_SCORE / {max_categories_hierarchy} --> |
| 12 | +<!-- Equals to TAG_SCORE / {max_categories_hierarchy} --> |
13 | 13 | {% assign CATEGORY_SCORE = 0.5 %}
|
14 | 14 |
|
15 |
| -{% assign SEPARATOR = ":" %} |
| 15 | +{% assign SEPARATOR = ':' %} |
16 | 16 |
|
17 |
| -{% assign score_list = "" | split: "" %} |
| 17 | +{% assign score_list = '' | split: '' %} |
18 | 18 | {% assign last_index = site.posts.size | minus: 1 %}
|
19 | 19 |
|
20 | 20 | {% for i in (0..last_index) %}
|
|
42 | 42 | {% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %}
|
43 | 43 | {% assign score_list = score_list | push: score_item %}
|
44 | 44 | {% endif %}
|
45 |
| - |
46 | 45 | {% endfor %}
|
47 | 46 |
|
48 |
| - |
49 |
| -{% assign index_list = "" | split: "" %} |
| 47 | +{% assign index_list = '' | split: '' %} |
50 | 48 |
|
51 | 49 | {% if score_list.size > 0 %}
|
52 | 50 | {% assign score_list = score_list | sort | reverse %}
|
|
56 | 54 | {% endfor %}
|
57 | 55 | {% endif %}
|
58 | 56 |
|
59 |
| -<!-- Fill with the other newlest posts --> |
| 57 | +<!-- Fill with the other newlest posts --> |
60 | 58 | {% assign less = TOTAL_SIZE | minus: index_list.size %}
|
61 | 59 |
|
62 | 60 | {% if less > 0 %}
|
63 | 61 | {% for i in (0..last_index) %}
|
64 | 62 | {% assign post = site.posts[i] %}
|
65 |
| - {% if post.url != page.url %} |
| 63 | + {% if post.url != page.url %} |
66 | 64 | {% capture cur_index %}{{ i }}{% endcapture %}
|
67 | 65 | {% unless index_list contains cur_index %}
|
68 | 66 | {% assign index_list = index_list | push: cur_index %}
|
|
77 | 75 |
|
78 | 76 | {% if index_list.size > 0 %}
|
79 | 77 | <div id="related-posts" class="mb-2 mb-sm-4">
|
80 |
| - <h3 class="pt-2 mb-4 ml-1" |
81 |
| - data-toc-skip>{{ site.data.locales[site.lang].post.relate_posts }}</h3> |
| 78 | + <h3 |
| 79 | + class="pt-2 mb-4 ml-1" |
| 80 | + data-toc-skip |
| 81 | + > |
| 82 | + {{ site.data.locales[include.lang].post.relate_posts }} |
| 83 | + </h3> |
82 | 84 | <div class="card-deck mb-4">
|
83 |
| - {% for entry in index_list %} |
84 |
| - {% assign index = entry | plus: 0 %} |
85 |
| - {% assign post = site.posts[index] %} |
86 |
| - <div class="card"> |
87 |
| - <a href="{{ post.url | relative_url }}"> |
88 |
| - <div class="card-body"> |
89 |
| - {% include datetime.html date=post.date class="small" %} |
90 |
| - <h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3> |
91 |
| - <div class="text-muted small"> |
92 |
| - <p> |
93 |
| - {% include no-linenos.html content=post.content %} |
94 |
| - {{ content | markdownify | strip_html | truncate: 200 | escape }} |
95 |
| - </p> |
| 85 | + {% for entry in index_list %} |
| 86 | + {% assign index = entry | plus: 0 %} |
| 87 | + {% assign post = site.posts[index] %} |
| 88 | + <div class="card"> |
| 89 | + <a href="{{ post.url | relative_url }}"> |
| 90 | + <div class="card-body"> |
| 91 | + {% include datetime.html date=post.date class="small" lang=include.lang %} |
| 92 | + <h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3> |
| 93 | + <div class="text-muted small"> |
| 94 | + <p> |
| 95 | + {% include no-linenos.html content=post.content %} |
| 96 | + {{ content | markdownify | strip_html | truncate: 200 | escape }} |
| 97 | + </p> |
| 98 | + </div> |
96 | 99 | </div>
|
97 |
| - </div> |
98 |
| - </a> |
99 |
| - </div> |
100 |
| - {% endfor %} |
101 |
| - </div> <!-- .card-deck --> |
102 |
| - </div> <!-- #related-posts --> |
| 100 | + </a> |
| 101 | + </div> |
| 102 | + {% endfor %} |
| 103 | + </div> |
| 104 | + <!-- .card-deck --> |
| 105 | + </div> |
| 106 | + <!-- #related-posts --> |
103 | 107 | {% endif %}
|
0 commit comments