Synthesize issue ID from posts array

This commit is contained in:
Spotlight 2022-09-04 02:58:52 -05:00
commit dcbc12c293
No known key found for this signature in database
GPG key ID: 874AA355B3209BDC
2 changed files with 34 additions and 5 deletions

View file

@ -0,0 +1,23 @@
{% comment %}
By default, we'll assume we haven't found the index.
{% endcomment %}
{% assign page_index = 'Unknown' %}
{%- for possible_post in site.posts -%}
{%- if possible_post.title == post.title -%}
{%- assign page_index = forloop.rindex -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{% comment %}
If we found an index, zero pad it, if necessary.
Thank you to https://stackoverflow.com/a/37453646 for this solution!
{% endcomment %}
{%- if page_index != 'Unknown' -%}
{%- assign page_index = page_index | prepend: '00' | slice: -2, 2 -%}
{%- endif -%}
Issue {{ page_index }} - {{ post.date | date: "%B %-d, %Y" }}

16
news.md
View file

@ -18,10 +18,14 @@ layout: news-post
The following is an example of a news post's content:
## Title
Content
Introduction
— Name
### Subheading
Content
### Subheading
Content
— Author Name
-->
{% comment %}
@ -30,9 +34,10 @@ Content
{% for post in site.posts limit: 3 %}
<h1>
<a href="{{ post.url }}">
{{ post.title }} - {{ post.date | date: "%B %-d, %Y" }}
{{ post.title }}
</a>
</h1>
<h3>{% include news-post-index.html post=post %}</h3>
{{ post.content }}
{% endfor %}
@ -45,9 +50,10 @@ Content
{% for post in site.posts offset: 3 %}
<h2>
<a href="{{ post.url }}">
{{ post.title }} - {{ post.date | date: "%B %-d, %Y" }}
{{ post.title }}
</a>
</h2>
<h3>{% include news-post-index.html post=post %}</h3>
{{ post.content | strip_html | truncatewords: 50 }}
{% endfor %}