Skip to content

Commit

Permalink
plugins: ensure the community plugin considers all missions
Browse files Browse the repository at this point in the history
The code used on `/annuaire` uses the Community plugin which allows
querying everybody that's active, and everybody that's not (i.e:
alumni).

To figure out if they are alumni, it was grabbing the last
mission (missions.last) and comparing the end date with today. That's
fair but it turns out that our member files are, obviously, not always
sorted chronologically.

Some of them have an early mission (early in the array) that's still
active, but with the previous logic it's only the last mission
considered hence why they don't appaear in the current members tab.

So instead use the glorious DSL (lib/member.rb) again to wrap the data
and query for any `active_missions` which removes some duplicate logic
and the display bug as well.
  • Loading branch information
freesteph committed Nov 27, 2024
1 parent 5cb5671 commit c1cd721
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 3 additions & 7 deletions _plugins/community.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# frozen_string_literal: true

require_relative '../lib/models/member'

module Jekyll
module CommunityFilter
def community(people, state, sort_by = 'oldest')
now = Date.today

past, current = people.partition do |person|
date = person.data['missions']&.last&.dig('end')

date && date <= now
end
current, past = people.partition { |person| Beta::Member.new(person.data).active_missions.any? }

result = state == 'past' ? past : current

Expand Down
20 changes: 20 additions & 0 deletions spec/plugins/community_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ def member_with(name:, end_date: nil, start_date: nil)
expect(past).to contain_exactly alum
end

context 'when the member has an active mission earlier in the missions array' do
before do
active_mission = { end_date: Date.today.tomorrow }

alum.data['missions'].prepend(active_mission)
end

it 'counts them as active' do
current = template.community(members, 'current')

expect(current).to include alum
end

it 'does not count them as alumni' do
past = template.community(members, 'past')

expect(past).to be_empty
end
end

it 'sorts them by newest mission start by default' do
expect(template.community(members, 'current')).to start_with(with_end)
end
Expand Down

0 comments on commit c1cd721

Please sign in to comment.