Skip to content

Commit 6f77d84

Browse files
Merge branch 'parametrize_event_include'
2 parents 5ddf44f + 87505f0 commit 6f77d84

12 files changed

+154
-139
lines changed

_includes/event.html

-57
This file was deleted.

_includes/events_array_generator.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% comment %}
2+
This include is to generate a list of posts for use in views.
3+
The array posts is to be used then in the view.
4+
Parameters:
5+
- future_events: (bool) Include future events in the array?
6+
If future_events is true, no past events will be added.
7+
If it is false, only past events are added.
8+
Default: false.
9+
- limit: (int) How many events to add to the array.
10+
Default: 0 (no limit).
11+
Creates variable for use in the outer scope:
12+
- posts (array) Array of post objects.
13+
{% endcomment %}
14+
15+
{% if include.future_events %}
16+
{% assign future_events = include.future_events %}
17+
{% else %}
18+
{% assign future_events = false %}
19+
{% endif %}
20+
{% if include.limit %}
21+
{% assign limit = include.limit %}
22+
{% endif %}
23+
24+
{% assign post_count = 0 %}
25+
{% assign curDate = site.time | date: "%s" %}
26+
{% assign posts = "" | split: ',' %}
27+
{% for post in site.posts %}
28+
{% assign postStartDate = post.date | date: "%s" %}
29+
{% if future_events %}
30+
<!--Add only future post-->
31+
{% if postStartDate >= curDate %}
32+
{% assign posts = posts | push: post %}
33+
{% assign post_count = post_count | plus: 1 %}
34+
{% endif %}
35+
<!--Add only past post-->
36+
{% else %}
37+
{% if postStartDate < curDate %}
38+
{% assign posts = posts | push: post %}
39+
{% assign post_count = post_count | plus: 1 %}
40+
{% endif %}
41+
{% endif %}
42+
43+
{% if post_count == limit | default: 0 %}
44+
{% break %}
45+
{% endif %}
46+
{% endfor %}
47+

_includes/footer.html

+6-34
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,19 @@ <h2 class="footer__section-title">Find Us Online</h2>
99
<div class="col-md-6">
1010
<h2 class="footer__section-title">Our Sponsors</h2>
1111
<hr class="footer__divider">
12-
{% comment %}
13-
Assume number of sponsors is even. We are going to create rows of 2 sponsors in each.
14-
If not even the last row must contain 1 sponsor and be terminated with appropriate tags.
15-
{% endcomment %}
16-
12+
<!--Create an array of permanent sponsors-->
1713
{% assign sponsors = "" | split: ',' %}
1814
{% for sponsor in site.sponsors %}
1915
{% if sponsor.permanent %}
2016
{% assign sponsors = sponsors | push: sponsor %}
2117
{% endif %}
2218
{% endfor %}
23-
{% assign num_of_sponsors = sponsors | size %}
24-
{% assign sponsors_remainder = num_of_sponsors | modulo: 2 %}
25-
26-
{% if sponsors_remainder == 0 %}
27-
{% assign num_of_sponsors_even = true %}
28-
{% assign row_num_modifier = 1 %}
29-
{% else %}
30-
{% assign num_of_sponsors_even = false %}
31-
{% assign row_num_modifier = 0 %}
32-
{% endif %}
33-
34-
{% assign num_of_rows = num_of_sponsors | divided_by: 2 | floor | minus: row_num_modifier %}
35-
{% assign items_per_row = 1 %}
3619

37-
{% for row in (0..num_of_rows) %}
38-
{% if forloop.last and num_of_sponsors_even == false %}
39-
{% assign items_per_row = 0 %}
40-
{% endif %}
41-
<div class="row">
42-
{% for col in (0..items_per_row) %}
43-
{% assign sponsor_index = row | times: 2 | plus: col %}
44-
{% assign sponsor = sponsors[sponsor_index] %}
45-
<div class="footer__sponsor-col col-md-12 col-lg-6">
46-
<a class="footer__sponsor-link" href="{{ sponsor.sponsor_link }}">
47-
<img class="footer__img" src="{{ site.baseurl }}/{{ sponsor.sponsor_logo }}">
48-
</a>
49-
</div>
50-
{% endfor %}
51-
</div>
52-
{% endfor %}
20+
{%
21+
include row_display_outer_loop.html
22+
items_array = sponsors
23+
inner_layout = "footer_sponsors_inner_layout.html"
24+
%}
5325
</div>
5426
<div class="col-md-3">
5527
<h2 class="footer__section-title">Python Sprints</h2>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="footer__sponsor-col col-md-12 col-lg-6">
2+
<a class="footer__sponsor-link" href="{{ include.item.sponsor_link }}">
3+
<img class="footer__img" src="{{ site.baseurl }}/{{ include.item.sponsor_logo }}">
4+
</a>
5+
</div>

_includes/inline_style_index.html

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
<!--Create array of future events-->
2-
{% assign upcoming_events = "" | split: ',' %}
3-
{% assign curDate = site.time | date: "%s" %}
4-
{% for post in site.posts %}
5-
{% assign postStartDate = post.date | date: "%s" %}
6-
{% if postStartDate >= curDate %}
7-
{% assign upcoming_events = upcoming_events | push: post %}
8-
{% endif %}
9-
{% endfor %}
10-
{% if upcoming_events.size > 0 %}
1+
{% include events_array_generator.html future_events = true %}
2+
{% if posts.size > 0 %}
113
{% assign upcoming_event = true %}
12-
{% assign post = upcoming_events | last %}
4+
{% assign post = posts | last %}
135

146
{% if post.image %}
157
{% assign image = post.image %}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="no-gutters__col col-sm-6">
2+
<div class="events__spacer"></div>
3+
<div class="events__img-container">
4+
<div class="events__img-overlay">
5+
<a class="events__link" href="{{ include.item.url }}">
6+
<i class="events__icon fas fa-external-link-square-alt"></i>
7+
</a>
8+
<div class="events__title-container">
9+
<h2 class="events__img-title">Event: {{ include.item.title }}</h2>
10+
<p class="events__img-subtitle">{{ include.item.venue }}, {{ include.item.date | date: "%e %B %Y" }}</p>
11+
</div>
12+
</div>
13+
<img class="events__img img-fluid" src="{{ site.baseurl }}/{{ include.item.image }}">
14+
</div>
15+
</div>

_includes/recent_events_section.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<section class="events">
2+
<div class="container-fluid">
3+
<div class="row">
4+
<div class="col-md-12">
5+
<h2 class="section-title">Recent Events</h2>
6+
</div>
7+
</div>
8+
{% include events_array_generator.html limit = 4 %}
9+
{%
10+
include row_display_outer_loop.html
11+
items_array = posts
12+
inner_layout = "recent_event_inner_layout.html"
13+
%}
14+
</div>
15+
</section>

_includes/row_display_outer_loop.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% comment %}
2+
This include is to easily pass an array to iterate over its items and
3+
a html layout to the generate 2 items per row look in the view.
4+
Parameters:
5+
- items_array: (array) Array of objects we want to show.
6+
- inner_layout: (string) Path to the html inner layout.
7+
{% endcomment %}
8+
9+
{% assign num_of_items = include.items_array | size %}
10+
{% assign items_array_remainder = num_of_items | modulo: 2 %}
11+
12+
{% if items_array_remainder == 0 %}
13+
{% assign num_of_items_even = true %}
14+
{% assign row_num_modifier = 1 %}
15+
{% else %}
16+
{% assign num_of_items_even = false %}
17+
{% assign row_num_modifier = 0 %}
18+
{% endif %}
19+
20+
{% assign num_of_rows = num_of_items | divided_by: 2 | floor | minus: row_num_modifier %}
21+
{% assign items_per_row = 1 %}
22+
23+
{% for row in (0..num_of_rows) %}
24+
{% if forloop.last and num_of_items_even == false %}
25+
{% assign items_per_row = 0 %}
26+
{% endif %}
27+
<div class="row">
28+
{% for col in (0..items_per_row) %}
29+
{% assign item_index = row | times: 2 | plus: col %}
30+
{% assign item = include.items_array[item_index] %}
31+
{% include {{ include.inner_layout }} item = item %}
32+
{% endfor %}
33+
</div>
34+
{% endfor %}

_includes/sponsors_inner_layout.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="footer__sponsor-col col-md-12 col-lg-6">
2+
<a class="footer__sponsor-link" href="{{ include.item.sponsor_link }}">
3+
<img class="footer__img"
4+
src="{{ site.baseurl }}/{{ include.item.sponsor_logo }}"
5+
alt="Sponsor logo">
6+
</a>
7+
</div>

_pages/03_events.html

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ <h2 class="events-page__page-subtitle">See what's coming up and what we did rece
3232
<div class="row">
3333
<div class="col-12">
3434
<h2 class="events-page__upcoming-title">Upcoming Events</h2>
35+
{% include events_array_generator.html future_events = true %}
36+
{% for post in posts %}
37+
<p>{{ post.title }}</p>
38+
{% endfor %}
3539
</div>
3640
</div>
3741
</div>
@@ -40,6 +44,10 @@ <h2 class="events-page__upcoming-title">Upcoming Events</h2>
4044
<div class="row">
4145
<div class="col-12">
4246
<h2 class="events-page__recent-title">Recent Events</h2>
47+
{% include events_array_generator.html %}
48+
{% for post in posts %}
49+
<p>{{ post.title }}</p>
50+
{% endfor %}
4351
</div>
4452
</div>
4553
</div>

_sass/style.scss

+6
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ a {
317317
margin-bottom: 0.5em;
318318
}
319319

320+
.upcoming__sponsor-col {
321+
background: rgba(7, 41, 72, 0.52);
322+
border: $dark-blue 2px groove;
323+
border-radius: 0 5px 5px 5px;
324+
}
325+
320326
.upcoming__img-container {
321327
background-size: cover;
322328
background-position: center center;

index.html

+8-37
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,11 @@ <h2 class="upcoming__event-label">Sponsors</h2>
116116
</div>
117117
</div>
118118
<div class="row">
119-
<div class="upcoming__event-title col-12">
119+
<div class="upcoming__sponsor-col col-12">
120120
{% assign site_sponsors_all = "" | split: ',' %}
121121
{% for sponsor in site.sponsors %}
122-
{% assign site_sponsors_all = site_sponsors_all | push: sponsor %}
122+
{% assign site_sponsors_all = site_sponsors_all | push: sponsor %}
123123
{% endfor %}
124-
125124
<!--Build an array of sponsors for the event.-->
126125
{% assign event_sponsors = "" | split: ',' %}
127126
{% for sponsor in post.sponsors %}
@@ -131,39 +130,11 @@ <h2 class="upcoming__event-label">Sponsors</h2>
131130
{% endif %}
132131
{% endfor %}
133132
{% endfor %}
134-
135-
{% assign num_of_sponsors = event_sponsors | size %}
136-
{% assign sponsors_remainder = num_of_sponsors | modulo: 2 %}
137-
138-
{% if sponsors_remainder == 0 %}
139-
{% assign num_of_sponsors_even = true %}
140-
{% assign row_num_modifier = 1 %}
141-
{% else %}
142-
{% assign num_of_sponsors_even = false %}
143-
{% assign row_num_modifier = 0 %}
144-
{% endif %}
145-
146-
{% assign num_of_rows = num_of_sponsors | divided_by: 2 | floor | minus: row_num_modifier %}
147-
{% assign items_per_row = 1 %}
148-
149-
{% for row in (0..num_of_rows) %}
150-
{% if forloop.last and num_of_sponsors_even == false %}
151-
{% assign items_per_row = 0 %}
152-
{% endif %}
153-
<div class="row">
154-
{% for col in (0..items_per_row) %}
155-
{% assign sponsor_index = row | times: 2 | plus: col %}
156-
{% assign sponsor = event_sponsors[sponsor_index] %}
157-
<div class="footer__sponsor-col col-md-12 col-lg-6">
158-
<a class="footer__sponsor-link" href="{{ sponsor.sponsor_link }}">
159-
<img class="footer__img"
160-
src="{{ site.baseurl }}/{{ sponsor.sponsor_logo }}"
161-
alt="Sponsor logo">
162-
</a>
163-
</div>
164-
{% endfor %}
165-
</div>
166-
{% endfor %}
133+
{%
134+
include row_display_outer_loop.html
135+
items_array = event_sponsors
136+
inner_layout = "sponsors_inner_layout.html"
137+
%}
167138
</div>
168139
</div>
169140
</div>
@@ -188,7 +159,7 @@ <h2 class="upcoming__event-label">Sponsors</h2>
188159
{% endif %}
189160

190161
<!--Events in the past section-->
191-
{% include event.html %}
162+
{% include recent_events_section.html %}
192163

193164
<!--Services section-->
194165
<section class="services">

0 commit comments

Comments
 (0)