forked from
mackuba.eu/sdk.blue
A curated list of libraries & SDKs for the Bluesky API and AT Protocol
1def first_nonempty(list)
2 list.compact.detect { |x| x.strip.length > 0 }
3end
4
5def latest_of(list, field)
6 list.compact.sort_by { |x| x[field] }.last
7end
8
9def merge_infos(infos)
10 {
11 'name' => infos[0]['name'],
12 'user_login' => infos[0]['user_login'],
13 'user_profile' => infos[0]['user_profile'],
14
15 'description' => first_nonempty(infos.map { |x| x['description'] }),
16 'homepage' => first_nonempty(infos.map { |x| x['homepage'] }),
17 'license' => first_nonempty(infos.map { |x| x['license'] }),
18 'user_name' => first_nonempty(infos.map { |x| x['user_name'] }),
19
20 'last_release' => latest_of(infos.map { |x| x['last_release'] }, 'published_at'),
21 'last_tag' => latest_of(infos.map { |x| x['last_tag'] }, 'committer_date'),
22 'last_commit' => latest_of(infos.map { |x| x['last_commit'] }, 'committer_date'),
23
24 'stars' => infos.map { |x| x['stars'] || 0 }.reduce(&:+)
25 }
26end
27
28Jekyll::Hooks.register :site, :post_read do |site|
29 data = site.data
30 data['projects'].each do |key, section|
31 section['repos'].each do |repo|
32 if repo['urls']
33 repo['info'] = repo['urls'].map { |u| data['metadata'][u] }.compact.then { |x| merge_infos(x) }
34 else
35 repo['info'] = data['metadata'][repo['url']]
36 end
37 end
38 end
39end