Skip to content

Instantly share code, notes, and snippets.

@brennanbrown
Created February 6, 2023 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennanbrown/b471a01e966c3f7e0b2669e6e4057b0c to your computer and use it in GitHub Desktop.
Save brennanbrown/b471a01e966c3f7e0b2669e6e4057b0c to your computer and use it in GitHub Desktop.
Displaying posts in Jekyll, organized by month. (Originally used on journalbar)
---
layout: default
---
<div class="home">
{% include header.html %}
{% include intro.html %}
<hr>
<section>
<h1 id="posts">
Weekly Posts
</h1>
<!-- https://gist.github.com/tuananh/7432553 -->
{% assign postsByYearMonth = site.posts | group_by_exp:"post", "post.date | date: '%B %Y'" %}
{% for yearMonth in postsByYearMonth %}
<h2>{{ yearMonth.name }}</h2>
<ul class="post-list">
{% for post in yearMonth.items %}
<li>
<time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%a, %b. %d" }}</time>
<a href="{{ post.url | prepend: site.baseurl | prepend: site.url }}">{{ post.title }}</a><br>
<small>
<em>{{ post.content | strip_html | escape | truncate: 300}}</em>
</small>
</li><br>
{% endfor %}
</ul>
{% endfor %}
</section>
</div>
<hr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment