Skip to content

Commit

Permalink
Add filtered event block to student pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdoc committed Sep 21, 2024
1 parent a2f4fa9 commit 990e1c8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/_includes/blocks/cal/eventsUpcoming.njk
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
{% set eventCount = 4 %}

{% if eventFilter %}
{% set taggedEvents = events | eventsFuture | eventsTagged(eventFilter) | eventsSort | limit(4) %}
{% endif %}

{% if eventFilter and taggedEvents|length == 0 %}
<!-- No events to display -->
{% else %}

<section class="m-4 border border-cream lg:container mx-auto sm:my-8">
<div class="justify-between items-center p-4 pb-0 sm:pb-4 sm:border-b sm:flex sm:gap-4">
<h2 class="glbHeading">Upcoming events</h2>
<a href="/calendar" class="text-blue decoration-orange">See the church calendar</a>
</div>

<div class="p-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
{% set eventCount = 4 %}
{% if eventFilter and taggedEvents %}

{% for event in taggedEvents %}
{% include 'blocks/cal/simpleEvent.njk' %}
{% endfor %}

{% set featuredEvent = events | eventsFuture | eventsFeatured | eventsSort | limit(1) | first %}
{% if featuredEvent %}
{% set event = featuredEvent %}
{% include 'blocks/cal/simpleEvent.njk' %}
{% set eventCount = 3 %}
{% endif %}
{% else %}


{% set soonEvents = events | eventsFuture(0, 'day') | eventsSort | limit(eventCount + 1) %}
{% set displayedEvents = 0 %}
{% for event in soonEvents %}
{% if event.title == featuredEvent.title or displayedEvents == eventCount%}
{# nothing to see here #}
{% else %}
{% set featuredEvent = events | eventsFuture | eventsFeatured | eventsSort | limit(1) | first %}
{% if featuredEvent %}
{% set event = featuredEvent %}
{% include 'blocks/cal/simpleEvent.njk' %}
{% set displayedEvents = displayedEvents + 1 %}
{% set eventCount = 3 %}
{% endif %}

{% endfor %}
{% set soonEvents = events | eventsFuture(0, 'day') | eventsSort | limit(eventCount + 1) %}
{% set displayedEvents = 0 %}
{% for event in soonEvents %}
{% if event.title == featuredEvent.title or displayedEvents == eventCount%}
{# nothing to see here #}
{% else %}
{% include 'blocks/cal/simpleEvent.njk' %}
{% set displayedEvents = displayedEvents + 1 %}
{% endif %}

{% endfor %}

{% endif %}
</div>
</section>

{%endif %}
6 changes: 6 additions & 0 deletions src/_utils/11ty.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ module.exports = {
});
},

eventsTagged: (events, tagName) => {
return events.filter(event => {
return event.data.tags && event.data.tags.includes(tagName);
});
},

eventsSort: (events) => {
return events.sort((a, b) => {
if (a.startDate > b.startDate) {
Expand Down
9 changes: 9 additions & 0 deletions src/augmentedPages/students.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
pagePosition: bottom
---

<div class="mt-12 px-4">
{% set eventFilter = 'students' %}
{% include 'blocks/cal/eventsUpcoming.njk' %}
{% set eventFilter = null %}
</div>

0 comments on commit 990e1c8

Please sign in to comment.