mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-02-07 06:19:01 +00:00
Add shorthand link macro for F-Droid
This commit is contained in:
parent
debf41c5a7
commit
7ddcd9be70
36
lib/asciidoctor/fdroid-link-inline-macro/README.adoc
Normal file
36
lib/asciidoctor/fdroid-link-inline-macro/README.adoc
Normal file
@ -0,0 +1,36 @@
|
||||
= F-droid link inline macro
|
||||
:toc:
|
||||
|
||||
|
||||
An inline macro as a shorthand for F-droid links.
|
||||
|
||||
|
||||
== Synopsis
|
||||
|
||||
[source, asciidoc]
|
||||
----
|
||||
fdroid:$APP_ID[$CAPTION]
|
||||
----
|
||||
|
||||
Where...
|
||||
|
||||
- `$APP_ID` is the application ID of the program (e.g., `org.moire.ultrasonic`).
|
||||
|
||||
- `$CAPTION` is the link text.
|
||||
By default, it will use the display name of the application from its link:https://gitlab.com/fdroid/fdroiddata/[metadata repository].
|
||||
In other words, it will create an additional network request.
|
||||
|
||||
|
||||
== Attributes
|
||||
|
||||
- `lang` is the language page to be linked.
|
||||
By default, it links to the English page of `en`.
|
||||
|
||||
|
||||
== Example usage
|
||||
|
||||
- `fdroid:org.moire.ultrasonic[]` should link to the link:https://f-droid.org/en/packages/org.moire.ultrasonic/[F-Droid page for Ultrasonic] with the link text 'Ultrasonic'.
|
||||
|
||||
- `fdroid:org.moire.ultrasonic[Hello there]` is the same as previous item but with the link text replaced with 'Hello there'.
|
||||
|
||||
- `fdroid:org.moire.ultrasonic[lang=it]` is the same as the first list item but links to the link:https://f-droid.org/it/packages/org.moire.ultrasonic/[Italian page].
|
29
lib/asciidoctor/fdroid-link-inline-macro/extension.rb
Normal file
29
lib/asciidoctor/fdroid-link-inline-macro/extension.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'open-uri'
|
||||
require 'open-uri/cached'
|
||||
require 'yaml'
|
||||
|
||||
class FDroidLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||
use_dsl
|
||||
|
||||
named :fdroid
|
||||
name_positional_attributes 'caption'
|
||||
default_attributes 'lang' => 'en'
|
||||
|
||||
def process(parent, target, attrs)
|
||||
doc = parent.document
|
||||
|
||||
app_id = target
|
||||
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) }
|
||||
attrs['caption'] = metadata['AutoName']
|
||||
end
|
||||
|
||||
url = %(https://f-droid.org/#{attrs['lang']}/packages/#{app_id})
|
||||
doc.register :links, url
|
||||
create_anchor parent, attrs['caption'], type: :link, target: url
|
||||
end
|
||||
end
|
@ -16,6 +16,7 @@ require_relative 'chat-block-processor/extension'
|
||||
require_relative 'git-blob-include-processor/extension'
|
||||
require_relative 'wikipedia-inline-macro/extension'
|
||||
require_relative 'package-indices-link-macro/extension'
|
||||
require_relative 'fdroid-link-inline-macro/extension'
|
||||
|
||||
Asciidoctor::Extensions.register do
|
||||
inline_macro ManInlineMacro
|
||||
@ -38,4 +39,5 @@ Asciidoctor::Extensions.register do
|
||||
inline_macro CtanLinkInlineMacro
|
||||
inline_macro PypiLinkInlineMacro
|
||||
inline_macro CratesIOLinkInlineMacro
|
||||
inline_macro FDroidLinkInlineMacro
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user