Skip to content

Commit

Permalink
Merge pull request #6 from vindevoy/master
Browse files Browse the repository at this point in the history
Fix issue 5 - Archive page not grouping posts by month in thymeleaf template
  • Loading branch information
jonbullock authored Nov 16, 2018
2 parents 79e2d59 + 8e76c60 commit 414e641
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
30 changes: 24 additions & 6 deletions templates/archive.thyme
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@
<h1>Blog Archive</h1>
</div>

<div th:each="post : ${posts}" th:with='last_month=null' th:remove='tag'>
<h3 th:if='${last_month!=#dates.format(post.date,"MMMM yyyy")}' th:text='${#dates.format(post.date,"MMMM yyyy")}'>June 2014</h3>

<h4><span th:text='${#dates.format(post.date,"dd")}' th:remove='tag'/> - <a th:href="${content.rootpath+post.uri}" th:text='${post.title}' href="foo.html">Post title</a></h4>
<span th:remove='all' th:with='last_month = ${#dates.format(post.date,"MMMM yyyy")}'/>
</div>
<th:block th:with="total_posts = *{#lists.size(published_posts)}">
<th:block th:if="*{total_posts != 0}" th:with="first_post = *{posts[0]}">
<h3 th:text="*{#dates.format(first_post.date,'MMMM yyyy')}">June 2014</h3>

<h4>
<span class="font-weight-bold" th:text="*{#dates.format(first_post.date,'dd')}"/> -
<a th:href="*{content.rootpath + first_post.uri}" th:text="*{first_post.title}" href="">Post Title</a>
</h4>

<th:block th:if="*{total_posts &gt; 1}" th:each="i : *{#numbers.sequence( 1, total_posts - 1)}">
<th:block th:with="previous_post = *{posts[i - 1]}, current_post = *{posts[i]}">
<th:block th:if="*{#dates.format(previous_post.date,'MMMM yyyy')} != *{#dates.format(current_post.date,'MMMM yyyy')}">
<p></p>
<h3 th:text="*{#dates.format(current_post.date,'MMMM yyyy')}">July 2014</h3>
</th:block>

<h4>
<span class="font-weight-bold" th:text="*{#dates.format(current_post.date,'dd')}"/> -
<a th:href="*{content.rootpath + current_post.uri}" th:text="*{current_post.title}" href="">Post Title</a>
</h4>
</th:block>
</th:block>
</th:block>
</th:block>

</div>
</div>
Expand Down
31 changes: 25 additions & 6 deletions templates/tags.thyme
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@
<h1 th:text="'Tag: '+${tag}">tag</h1>
</div>

<div th:each="post : ${tag_posts}" th:with='last_month=null' th:remove='tag'>
<h3 th:if='${last_month!=#dates.format(post.date,"MMMM yyyy")}' th:text='${#dates.format(post.date,"MMMM yyyy")}'>June 2014</h3>

<h4><span th:text='${#dates.format(post.date,"dd")}' th:remove='tag'/> - <a th:href="${content.rootpath+post.uri}" th:text='${post.title}' href="foo.html">Post title</a></h4>
<span th:remove='all' th:with='last_month = ${#dates.format(post.date,"MMMM yyyy")}'/>
</div>
<th:block th:with="total_posts = *{#lists.size(tag_posts)}">
<th:block th:if="*{total_posts != 0}" th:with="first_post = *{posts[0]}">
<h3 th:text="*{#dates.format(first_post.date,'MMMM yyyy')}">June 2014</h3>

<h4>
<span class="font-weight-bold" th:text="*{#dates.format(first_post.date,'dd')}"/> -
<a th:href="*{content.rootpath + first_post.uri}" th:text="*{first_post.title}" href="">Post Title</a>
</h4>

<th:block th:if="*{total_posts &gt; 1}" th:each="i : *{#numbers.sequence( 1, total_posts - 1)}">
<th:block th:with="previous_post = *{posts[i - 1]}, current_post = *{posts[i]}">
<th:block th:if="*{#dates.format(previous_post.date,'MMMM yyyy')} != *{#dates.format(current_post.date,'MMMM yyyy')}">
<p></p>
<h3 th:text="*{#dates.format(current_post.date,'MMMM yyyy')}">July 2014</h3>
</th:block>

<h4>
<span class="font-weight-bold" th:text="*{#dates.format(current_post.date,'dd')}"/> -
<a th:href="*{content.rootpath + current_post.uri}" th:text="*{current_post.title}" href="">Post Title</a>
</h4>
</th:block>
</th:block>
</th:block>
</th:block>

</div>
</div>

Expand Down

0 comments on commit 414e641

Please sign in to comment.