Skip to content

Commit 6881dad

Browse files
Modified event.html to test if post was in the past (since we want to show upcoming events).
Created 2 future dated dummy posts to test looping and displaying their content on main page - new section layout is required. Added test upcoming events section to index.html which shows only future dated posts.
1 parent d0310c7 commit 6881dad

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

_config_dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include: ["_pages"]
1919
exclude:
2020
- Gemfile
2121
- Gemfile.lock
22+
future: true
2223

2324
# command to run build locally:
2425
# bundle exec jekyll serve --config _config.yml,_config_dev.yml

_includes/event.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ <h2 class="section-title">Recent Events</h2>
88

99
{% comment %}
1010
Create an array of last 4 posts (from newest to oldest) to show in recent events section.
11+
Since we also allow future posts to show upcoming event we have to eliminate the future once
12+
from displaying in the past ones.
1113
{% endcomment %}
1214

15+
{% assign curDate = site.time | date: "%s" %}
1316
{% assign last_4_posts = "" | split: ',' %}
14-
{% for post in site.posts reversed limit: 4 %}
15-
{% assign last_4_posts = last_4_posts | push: post %}
17+
{% for post in site.posts %}
18+
{% assign postStartDate = post.date | date: "%s" %}
19+
{% if postStartDate <= curDate %}
20+
{% assign last_4_posts = last_4_posts | push: post %}
21+
{% increment post_count %}
22+
{% endif %}
23+
{% if post_count == 4 %}
24+
{% break %}
25+
{% endif %}
1626
{% endfor %}
1727

1828
{% comment %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
layout: default
3+
title: This is test post in the future no 2 title
4+
date: 2022-10-04
5+
venue: Test venue 2
6+
link: www.blizzard.com
7+
image: static/images/events_past/pandas_bokeh_backend_harvey_nash_960x539px.jpeg
8+
---
9+
10+
Test post in the future 2 content
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
layout: default
3+
title: This is test post in the future no 1 title
4+
date: 2020-10-04
5+
venue: Test venue 1
6+
link: www.google.com
7+
image: static/images/events_past/pandas_bokeh_backend_harvey_nash_960x539px.jpeg
8+
---
9+
10+
Test post in the future 1 content

index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ <h2 class="section-title">Our Mission</h2>
4646
</div>
4747
</section>
4848

49+
<section>
50+
<div class="row container">
51+
<div class="col-md-12">
52+
<!--Upcoming Events section-->
53+
<!--Create array of future events-->
54+
{% assign upcoming_events = "" | split: ',' %}
55+
{% assign curDate = site.time | date: "%s" %}
56+
{% for post in site.posts %}
57+
{% assign postStartDate = post.date | date: "%s" %}
58+
{% if postStartDate >= curDate %}
59+
{% assign upcoming_events = upcoming_events | push: post %}
60+
{% endif %}
61+
{% endfor %}
62+
63+
<!--Test data passed from future posts/events-->
64+
{% for post in upcoming_events %}
65+
<h1>Event: {{ post.title }}</h1>
66+
<h1>Venue: {{ post.venue }}</h1>
67+
<h1>Date: {{ post.date | date: "%e %B %Y" }}</h1>
68+
<a href="{{ post.link }}">test link</a>
69+
{% endfor %}
70+
</div>
71+
</div>
72+
</section>
73+
74+
4975
<!--Events in the past section-->
5076
{% include event.html %}
5177

0 commit comments

Comments
 (0)