Skip to content

Commit a4e6d4c

Browse files
committed
Posts by date working
1 parent 2640ebc commit a4e6d4c

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

_config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ github:
3838

3939

4040
### Navbar Settings ###
41-
nav_exclude: # The following paths are excluded from navbar
41+
nav_exclude: # The following paths are excluded from navbar
4242
- pages/tags.html
43+
- pages/calendar.html
4344
- pages/404.html
4445
- pages/index.md
4546

_includes/blog/calendar.html

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
<!-- Group posts by date -->
2-
{%- assign posts_by_date = {} -%}
3-
{%- for post in site.posts -%}
4-
{%- assign post_date = post.date | date: "%Y-%m" -%} <!-- Group by year and month -->
5-
{%- if posts_by_date[post_date] == nil -%}
6-
{%- assign posts_by_date[post_date] = "" -%}
7-
{%- endif -%}
8-
{%- assign posts_by_date[post_date] = posts_by_date[post_date] | append: post.url | append: "|" -%}
9-
{%- endfor -%}
1+
{%- assign posts_by_date = site.posts | group_by_exp: "post", "post.date | date: '%Y-%m'" -%}
102

113
<!-- Create a dropdown list by date -->
12-
{% for date, posts in posts_by_date %}
13-
<div class="py-3">
14-
<h4 id="{{ date }}">{{ date }}</h4>
15-
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#posts-{{ date }}" aria-expanded="false" aria-controls="posts-{{ date }}">
16-
Ver posts
17-
</button>
18-
<div class="collapse" id="posts-{{ date }}">
4+
{% for group in posts_by_date %}
5+
<div class="py-0">
6+
<h4 class="date-item">
7+
<a href="javascript:void(0)" class="date-toggle" data-toggle="collapse" data-target="#posts-{{ group.name }}" aria-expanded="false" aria-controls="posts-{{ group.name }}">
8+
{{ group.name }}
9+
</a>
10+
</h4>
11+
<div class="collapse" id="posts-{{ group.name }}">
1912
<ol>
20-
{% assign post_urls = posts | split: '|' %}
21-
{% for post_url in post_urls %}
22-
{%- assign post = site.posts | where: "url", post_url | first -%}
13+
{% for post in group.items %}
2314
<li><a href="{{ post.url | relative_url }}">{{ post.title }}</a></li>
2415
<small class="text-muted"> - {{ post.date | date_to_long_string }}</small>
2516
<br/>

_sass/_blog.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@
2424
color: white !important;
2525
}
2626
}
27+
28+
.date-toggle {
29+
cursor: pointer;
30+
text-decoration: none;
31+
font-weight: bold;
32+
color: #007bff;
33+
}
34+
35+
.date-toggle:hover {
36+
text-decoration: underline;
37+
}

pages/calendar.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: page
3+
title: Calendar
4+
permalink: /blog/calendar
5+
---
6+
7+
{% include blog/calendar.html %}

0 commit comments

Comments
 (0)