Change default behavior for creating network requests when caption is unset

This commit is contained in:
Gabriel Arazas 2023-10-29 12:48:09 +08:00
parent bfbea57d6b
commit 924fd9eac5
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
3 changed files with 13 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -23,17 +23,15 @@ 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' metadata['name']
metadata['name'] when 'recording', 'release-group', 'release', 'cdstub', 'work'
when 'recording', 'release-group', 'release', 'cdstub', 'work' metadata['title']
metadata['title'] 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