Add Repology link inline macro

This commit is contained in:
Gabriel Arazas 2023-05-27 17:24:17 +08:00
parent c27fadcc9f
commit cef163c722
3 changed files with 48 additions and 0 deletions

View File

@ -18,6 +18,7 @@ require_relative 'wikipedia-inline-macro/extension'
require_relative 'package-indices-link-macro/extension'
require_relative 'fdroid-link-inline-macro/extension'
require_relative 'musicbrainz-link-inline-macro/extension'
require_relative 'repology-link-inline-macro/extension'
Asciidoctor::Extensions.register do
inline_macro ManInlineMacro
@ -43,4 +44,6 @@ Asciidoctor::Extensions.register do
inline_macro FDroidLinkInlineMacro
inline_macro MusicBrainzLinkInlineMacro
inline_macro RepologyLinkInlineMacro
end

View File

@ -0,0 +1,27 @@
= Repology link inline macro
:toc:
An inline macro for shorthands Repology links.
== Synopsis
[source, asciidoc]
----
repology:$PROJECT[$CAPTION]
----
Where...
- `$PROJECT` is the project name listed in link:https://repology.org/projects/[Repology's project list].
- `$CAPTION` is the link text to be used.
By default, it will use the project name.
== Example usage
- `repology:beets[]` should link to the link:https://repology.org/project/beets/[Beets project page in Repology] with `beets` as the link text.
- `repology:beets[widely available in Linux distributions]` is the same as the previous item but with the link text replaced to `widely available in Linux distributions`.

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
class RepologyLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :repology
name_positional_attributes 'caption'
def process(parent, target, attrs)
doc = parent.document
text = attrs['caption'] || target
url = %(https://repology.org/project/#{target})
doc.register :links, url
create_anchor parent, text, type: :link, target: url
end
end