mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Change default behavior for creating network requests when caption is unset
This commit is contained in:
parent
bfbea57d6b
commit
924fd9eac5
@ -16,10 +16,8 @@ class FDroidLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
app_id = target
|
app_id = target
|
||||||
app_metadata_uri = %(https://gitlab.com/fdroid/fdroiddata/-/raw/master/metadata/#{app_id}.yml)
|
app_metadata_uri = %(https://gitlab.com/fdroid/fdroiddata/-/raw/master/metadata/#{app_id}.yml)
|
||||||
|
|
||||||
if attrs['caption'].nil?
|
|
||||||
metadata = OpenURI.open_uri(app_metadata_uri) { |f| YAML.safe_load(f.read) }
|
metadata = OpenURI.open_uri(app_metadata_uri) { |f| YAML.safe_load(f.read) }
|
||||||
attrs['caption'] = metadata['AutoName']
|
attrs['caption'] ||= metadata['AutoName']
|
||||||
end
|
|
||||||
|
|
||||||
url = %(https://f-droid.org/#{attrs['lang']}/packages/#{app_id})
|
url = %(https://f-droid.org/#{attrs['lang']}/packages/#{app_id})
|
||||||
doc.register :links, url
|
doc.register :links, url
|
||||||
|
@ -23,10 +23,8 @@ class FlathubLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
'User-Agent' => ::Asciidoctor::FoodogsquaredCustomExtensions::USER_AGENT
|
'User-Agent' => ::Asciidoctor::FoodogsquaredCustomExtensions::USER_AGENT
|
||||||
}
|
}
|
||||||
|
|
||||||
if attrs['caption'].nil?
|
|
||||||
metadata = OpenURI.open_uri(app_metadata_uri, headers) { |f| JSON.parse(f.read) }
|
metadata = OpenURI.open_uri(app_metadata_uri, headers) { |f| JSON.parse(f.read) }
|
||||||
attrs['caption'] = metadata['name']
|
attrs['caption'] ||= metadata['name']
|
||||||
end
|
|
||||||
|
|
||||||
url = %(https://flathub.org/apps/#{app_id})
|
url = %(https://flathub.org/apps/#{app_id})
|
||||||
doc.register :links, url
|
doc.register :links, url
|
||||||
|
@ -23,7 +23,6 @@ class MusicBrainzLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
|
|
||||||
uri = %(#{root_endpoint}/#{attrs['type']}/#{target})
|
uri = %(#{root_endpoint}/#{attrs['type']}/#{target})
|
||||||
|
|
||||||
if attrs['caption'].nil?
|
|
||||||
metadata = OpenURI.open_uri(uri, headers) { |f| JSON.parse(f.read) }
|
metadata = OpenURI.open_uri(uri, headers) { |f| JSON.parse(f.read) }
|
||||||
attrs['caption'] ||= case attrs['type']
|
attrs['caption'] ||= case attrs['type']
|
||||||
when 'artist', 'area', 'events', 'genre', 'instrument', 'label', 'place', 'series'
|
when 'artist', 'area', 'events', 'genre', 'instrument', 'label', 'place', 'series'
|
||||||
@ -33,7 +32,6 @@ class MusicBrainzLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
when 'url'
|
when 'url'
|
||||||
metadata['resource']
|
metadata['resource']
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
target = %(https://musicbrainz.org/#{attrs['type']}/#{target})
|
target = %(https://musicbrainz.org/#{attrs['type']}/#{target})
|
||||||
doc.register :links, target
|
doc.register :links, target
|
||||||
|
Loading…
Reference in New Issue
Block a user