With this extension a git hash can be easily referenced. The porters handbook versions chapter uses this extension as an example in the FreeBSD 14.0 version table. An example of use gitref:hash[repository="src|doc|ports",length=hash-longitude] The repository should be src, doc or ports. And if no length it's specified the macro will use 12 characters of the specified hash. PR: 253050 Submitted by: jhb@
25 lines
562 B
Ruby
25 lines
562 B
Ruby
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
|
|
|
include ::Asciidoctor
|
|
|
|
class GitReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
use_dsl
|
|
|
|
named :gitref
|
|
|
|
def process parent, target, attrs
|
|
hash = target
|
|
repository = if (repository = attrs['repository'])
|
|
"#{repository}"
|
|
else
|
|
"src"
|
|
end
|
|
length = if (length = attrs['length'])
|
|
length.to_i
|
|
else
|
|
12
|
|
end
|
|
url = %(https://cgit.freebsd.org/#{repository}/commit/?id=#{hash})
|
|
%(<a href="#{url}">#{hash[0, length]}</a>)
|
|
end
|
|
end
|