13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/asciidoctor/foodogsquared/extensions/flathub-inline-macro.rb', line 13
def process(parent, target, attrs)
doc = parent.document
app_id = target
app_metadata_uri = %(https://flathub.org/api/v2/appstream/#{app_id})
= {
'Accept' => 'application/json',
'User-Agent' => ::Asciidoctor::Foodogsquared::USER_AGENT
}
metadata = OpenURI.open_uri(app_metadata_uri, ) { |f| JSON.parse(f.read) }
attrs['caption'] ||= metadata['name']
url = %(https://flathub.org/apps/#{app_id})
doc.register :links, url
create_anchor parent, attrs['caption'], type: :link, target: url
end
|