Skip to content

Commit

Permalink
better tags
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismdp committed Nov 25, 2024
1 parent 776dcdf commit 0c8cc9c
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,33 @@

<div>
{% for tag in page.categories %}
<h3>More on: {{ tag }}</h3>
<div class="post-list" style="margin-bottom:40px">
{% for post in site.categories[tag] | limit: 5 %}
{% if post.id != page.id %}
<div class="tag-entry">
<a href="{{- site.url -}}{{- post.url -}}">{{- post.title -}}</a>
<time class='text-xs opacity-50' datetime="{{- post.date | date_to_xmlschema -}}"> {{- post.date | date: "%b %Y" -}}</time>
</div>
{% endif %}
{%- endfor -%}
</div>
{% assign tag_posts = site.categories[tag] %}
{% assign related_posts = "" %}

{% for post in tag_posts %}
{% if post.id != page.id %}
{% assign related_posts = related_posts | append: post.id | append: "," %}
{% endif %}
{% endfor %}

{% assign related_posts_count = related_posts | split: "," | size | minus: 1 %}

{% if related_posts_count > 0 %}
<h3>More on: {{ tag }}</h3>
<div class="post-list" style="margin-bottom:40px">
{% assign related_posts_array = related_posts | split: "," | uniq %}
{% for post_id in related_posts_array limit: 5 %}
{% assign post = site.posts | where: "id", post_id | first %}
{% if post %}
<div class="tag-entry">
<a href="{{ site.url }}{{ post.url }}">{{ post.title }}</a>
<time class='text-xs opacity-50' datetime="{{ post.date | date_to_xmlschema }}">
{{ post.date | date: "%b %Y" }}
</time>
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% endfor %}
</div>

0 comments on commit 0c8cc9c

Please sign in to comment.