git: 1d899c1c6f - main - PackagesMacro: Extend the syntax to category/name@flavor[pkgname]

From: Li-Wen Hsu <>
Date: Sun, 19 Mar 2023 16:12:30 UTC
The branch main has been updated by lwhsu:


commit 1d899c1c6fc6b000411cc45fc2823caefc5af7e2
Author:     Li-Wen Hsu <>
AuthorDate: 2023-03-19 16:09:25 +0000
Commit:     Li-Wen Hsu <>
CommitDate: 2023-03-19 16:09:25 +0000

    PackagesMacro: Extend the syntax to category/name@flavor[pkgname]
    The package macro creates a link to the web interface of the port's
    origin directory in the ports repository.  Extend its usage to cover the
    case when we want to refer to a speicifed flavor of a port.
    For example, if we want to refer the aarch64-gcc12 pacakge, in the past
    we can only specify its origin port, like `pacakge:devel/freebsd-gcc12`,
    and unable to add the `@aarch64` flavor suffix because it creates a
    broken link.  This change makes it strip the suffix after `@` and accept
    a parameter of package name as link text.  If not provided, use the origin
    as the original behavior.
    Thus we can have this kind of notation:
    which creates linkt to:
    with link text:
    Reviewed by:    carlavilla, dbaio
    Differential Revision:
 shared/lib/PackagesMacro/extension.rb | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/shared/lib/PackagesMacro/extension.rb b/shared/lib/PackagesMacro/extension.rb
index 20969ca3c0..5476995c49 100644
--- a/shared/lib/PackagesMacro/extension.rb
+++ b/shared/lib/PackagesMacro/extension.rb
@@ -6,14 +6,23 @@ class PackagesMacro < Asciidoctor::Extensions::InlineMacroProcessor
   named :package
+  name_positional_attributes 'pkgname'
   def process parent, target, attrs
-    packagename = target
+    pkgorigin = target
-    target = %({target}/pkg-descr)
-    parent.document.register :links, target
+    if pkgorigin.include?("@")
+      pkgorigin = pkgorigin[0..pkgorigin.index("@")-1]
+    end
-    %(<a class="package" href="#{target}">#{packagename}</a>)
+    pkgname = if (pkgname = attrs['pkgname'])
+      "#{pkgname}"
+    else
+      "#{target}"
+    end
+    url = %({pkgorigin}/)
+    %(<a class="package" href="#{url}">#{pkgname}</a>)