Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/jekyll-webfinger.rb
1677 views
1
# frozen_string_literal: true
2
3
require './_plugins/gtn'
4
5
Jekyll::Hooks.register :site, :post_write do |site|
6
if Jekyll.env != 'production'
7
Jekyll.logger.info '[GTN/Webfinger] Skipping webfinger generation in development'
8
next
9
end
10
11
# Make the directory
12
Jekyll.logger.info '[GTN/Webfinger] Generating webfinger files'
13
FileUtils.mkdir_p "#{site.dest}/api/fedi"
14
15
Gtn::Contributors.list(site)
16
.select { |_k, v| v['fediverse'] }
17
.each do |k, v|
18
# saving the outputs to
19
# training-material/api/fedi/resource=acct%3Ahexylena%40galaxy.training.json
20
21
subscribe_url = if v['fediverse_flavor'] == 'mastodon'
22
"#{v['fediverse'].gsub(%r{/@[a-z]*$}, '')}/authorize_interaction?uri={uri}"
23
else
24
"#{v['fediverse'].gsub(%r{/[a-z]*$}, '')}/ostatus_subscribe?acct={uri}"
25
end
26
f2 = v['fediverse'].gsub(%r{https://(.*)/@?(.*)}, 'https://\1/users/\2')
27
profile = {
28
subject: "acct:#{k}@training.galaxyproject.org",
29
aliases: [
30
f2
31
],
32
links: [
33
{
34
rel: 'http://webfinger.net/rel/profile-page',
35
type: 'text/html',
36
href: f2,
37
},
38
{
39
rel: 'self',
40
type: 'application/activity+json',
41
href: f2 # ehhh
42
},
43
{
44
rel: 'self',
45
type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
46
href: f2,
47
},
48
{
49
rel: 'http://ostatus.org/schema/1.0/subscribe',
50
template: subscribe_url
51
}
52
]
53
}
54
path = "#{site.dest}/api/fedi/resource=acct:#{k}@training.galaxyproject.org.json"
55
File.write(path, profile.to_json)
56
57
path = "#{site.dest}/api/fedi/resource=acct:@#{k}@training.galaxyproject.org.json"
58
File.write(path, profile.to_json)
59
end
60
end
61
62