From cef163c722c8af5fa7db2588cfbaf4b3a6fd1f55 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 27 May 2023 17:24:17 +0800 Subject: [PATCH] Add Repology link inline macro --- lib/asciidoctor/foodogsquared-extensions.rb | 3 +++ .../repology-link-inline-macro/README.adoc | 27 +++++++++++++++++++ .../repology-link-inline-macro/extension.rb | 18 +++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 lib/asciidoctor/repology-link-inline-macro/README.adoc create mode 100644 lib/asciidoctor/repology-link-inline-macro/extension.rb diff --git a/lib/asciidoctor/foodogsquared-extensions.rb b/lib/asciidoctor/foodogsquared-extensions.rb index 788339c..72e744d 100644 --- a/lib/asciidoctor/foodogsquared-extensions.rb +++ b/lib/asciidoctor/foodogsquared-extensions.rb @@ -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 diff --git a/lib/asciidoctor/repology-link-inline-macro/README.adoc b/lib/asciidoctor/repology-link-inline-macro/README.adoc new file mode 100644 index 0000000..fe39352 --- /dev/null +++ b/lib/asciidoctor/repology-link-inline-macro/README.adoc @@ -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`. diff --git a/lib/asciidoctor/repology-link-inline-macro/extension.rb b/lib/asciidoctor/repology-link-inline-macro/extension.rb new file mode 100644 index 0000000..41d4694 --- /dev/null +++ b/lib/asciidoctor/repology-link-inline-macro/extension.rb @@ -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