mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-31 04:58:26 +00:00
Add GitLab link inline macro
This commit is contained in:
parent
4951495446
commit
9d48ee4926
@ -4,10 +4,12 @@ require_relative 'man-inline-macro/extension'
|
|||||||
require_relative 'swhid-inline-macro/extension'
|
require_relative 'swhid-inline-macro/extension'
|
||||||
require_relative 'github-raw-content-include-processor/extension'
|
require_relative 'github-raw-content-include-processor/extension'
|
||||||
require_relative 'gitlab-raw-content-include-processor/extension'
|
require_relative 'gitlab-raw-content-include-processor/extension'
|
||||||
|
require_relative 'gitlab-link-inline-macro/extension'
|
||||||
|
|
||||||
Asciidoctor::Extensions.register do
|
Asciidoctor::Extensions.register do
|
||||||
inline_macro ManInlineMacro
|
inline_macro ManInlineMacro
|
||||||
inline_macro SWHInlineMacro
|
inline_macro SWHInlineMacro
|
||||||
include_processor GitHubRawIncludeProcessor
|
include_processor GitHubRawIncludeProcessor
|
||||||
include_processor GitLabRawIncludeProcessor
|
include_processor GitLabRawIncludeProcessor
|
||||||
|
inline_macro GitLabLinkInlineMacro
|
||||||
end
|
end
|
||||||
|
33
gems/lib/asciidoctor/gitlab-link-inline-macro/README.adoc
Normal file
33
gems/lib/asciidoctor/gitlab-link-inline-macro/README.adoc
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
= GitLab link inline macro
|
||||||
|
:toc:
|
||||||
|
|
||||||
|
|
||||||
|
An inline macro for easily linking objects from GitLab instances.
|
||||||
|
|
||||||
|
|
||||||
|
== Synopsis
|
||||||
|
|
||||||
|
[source, asciidoc]
|
||||||
|
----
|
||||||
|
gitlab:$OWNER/$REPO[$CAPTION]
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
|
== Attributes
|
||||||
|
|
||||||
|
- `domain` is the base domain of the GitLab instance.
|
||||||
|
By default, it points to the official instance of `gitlab.com`.
|
||||||
|
|
||||||
|
- `rev` is the commit of the repo.
|
||||||
|
By default. it doesn't point to anything which should be in the default branch of the repository.
|
||||||
|
|
||||||
|
- `path` is the filepath to be linked.
|
||||||
|
|
||||||
|
|
||||||
|
== Example usage
|
||||||
|
|
||||||
|
- `gitlab:gitlab-org/gitlab[]` will link to link:https://gitlab.com/gitlab-org/gitlab[the GitLab's source code with the default domain].
|
||||||
|
|
||||||
|
- `gitlab:gitlab-org/gitlab[rev=0c9f77389424b6c5fd8e96b227e9125a13a07cb3, path=README.md]` should link to the link:https://gitlab.com/gitlab-org/gitlab/-/blob/0c9f77389424b6c5fd8e96b227e9125a13a07cb3/README.md[GitLab's README from 3 years ago].
|
||||||
|
|
||||||
|
- `gitlab:GNOME/mutter[domain=gitlab.gnome.org, rev=df653b95adf6462fc731998eb53b0860baa7253c, path=meson.build]` should link to link:https://gitlab.gnome.org/GNOME/mutter/-/blob/df653b95adf6462fc731998eb53b0860baa7253c/meson.build[Mutter v44.beta `meson.build` from GNOME GitLab instance].
|
24
gems/lib/asciidoctor/gitlab-link-inline-macro/extension.rb
Normal file
24
gems/lib/asciidoctor/gitlab-link-inline-macro/extension.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
require 'uri'
|
||||||
|
|
||||||
|
class GitLabLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||||
|
use_dsl
|
||||||
|
|
||||||
|
named :gitlab
|
||||||
|
name_positional_attributes 'caption'
|
||||||
|
default_attributes 'domain' => 'gitlab.com'
|
||||||
|
|
||||||
|
def process parent, target, attrs
|
||||||
|
doc = parent.document
|
||||||
|
|
||||||
|
text = attrs['caption'] || target
|
||||||
|
uri = URI.parse %(https://#{attrs['domain']}/#{target})
|
||||||
|
|
||||||
|
uri.path += %(/-/tree/#{attrs['rev']}) if attrs['rev']
|
||||||
|
uri.path += %(/#{attrs['path']}) if attrs['path']
|
||||||
|
|
||||||
|
target = uri.to_s
|
||||||
|
|
||||||
|
doc.register :links, target
|
||||||
|
create_anchor parent, text, type: :link, target: target
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user