Skip to content

Commit

Permalink
fix: add past class for events that have past
Browse files Browse the repository at this point in the history
  • Loading branch information
trovster committed Jun 17, 2024
1 parent a0eea38 commit be39c89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ const webcal = require('./src/_filters/webcal')
const { upcoming, limit, next } = require('./src/_filters/collections')

const showDate = require('./src/_methods/showDate')
const isPast = require('./src/_methods/isPast')

module.exports = config => {
config.addPlugin(EleventyHtmlBasePlugin)

// filters…
config.addFilter('date', date)
config.addFilter('absoluteUrl', absoluteUrl)
config.addFilter('validTags', validTags)
config.addFilter('webcal', webcal)
config.addFilter('isPast', isPast)

// collections…
config.addFilter('limit', limit)
config.addFilter('upcoming', upcoming)
config.addFilter('next', next)

// methods…
config.addNunjucksGlobal('showDate', showDate)
config.addNunjucksGlobal('isPast', isPast)

// shortcodes…
config.addShortcode('year', () => new Date().getFullYear())

config.addPassthroughCopy({
Expand Down
2 changes: 1 addition & 1 deletion src/_layouts/games.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ layout: base.njk
</thead>
<tbody>
{% for game in collections[tag] %}
<tr class="vevent">
<tr class="vevent {{ 'past' if isPast(game) }}">
<td class="datetime">
{% if showDate(game.data.date, loop.index0, collections[tag]) %}
<span class="day">{{ game.data.date | date('ddd DD MMM') }}</span>
Expand Down
3 changes: 3 additions & 0 deletions src/_methods/isPast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { DateTime } = require('luxon')

module.exports = post => DateTime.fromISO(post.data.endDate || post.data.date) <= DateTime.now()

0 comments on commit be39c89

Please sign in to comment.