forked from iris-hep/iris-hep.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge_area.rb
39 lines (29 loc) · 1.06 KB
/
challenge_area.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
require 'yaml'
require 'pathname'
require 'set'
def ensure_array(arr)
return [] if arr.nil?
arr.is_a?(Array) ? arr : [arr]
end
project_files = Pathname.glob('pages/projects/*.md')
counter = {}
project_files.each do |fn|
proj = YAML.load_file fn
fa = ensure_array proj['challenge-area']
team = ensure_array proj['team']
team.reject! { _1.include?(' ') }&.reject! { _1.include?('@') }
fa.each { |a| team.each { |t| counter[t] = (counter[t] || Set.new) << a } }
end
people_files = Pathname.glob('_data/people/*.yml')
people_files.each do |fn|
info = YAML.load_file fn
user_fa = info['presentations']&.flat_map { ensure_array(_1['challenge-area']) }&.to_set&.delete('core')
proj_fa = counter[info['shortname']]&.delete('core')
puts "#{info['name']}: #{user_fa.to_a} | #{proj_fa.to_a}"
all_fa = (user_fa || Set.new) | (proj_fa || Set.new)
info['challenge-area'] = all_fa.to_a unless all_fa.empty?
sorted = info.sort.to_h
sorted['presentations'] = sorted.delete 'presentations'
fn.write(sorted.to_yaml.lines[1..].join)
end