[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa-admin c29da22 424/439: * elpa-admin.el: Generate SVG badge
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa-admin c29da22 424/439: * elpa-admin.el: Generate SVG badges |
Date: |
Sun, 17 Oct 2021 15:48:50 -0400 (EDT) |
branch: elpa-admin
commit c29da22342f9fdf1bba419c71c1800d57a57373c
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* elpa-admin.el: Generate SVG badges
(elpaa--string-width, elpaa--make-badge): New functions.
(elpaa--make-one-package): Use `elpaa--make-badge`.
(elpaa--html-make-pkg): Add link to badge.
---
elpa-admin.el | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 105 insertions(+), 1 deletion(-)
diff --git a/elpa-admin.el b/elpa-admin.el
index 31d9c92..38ace62 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -647,6 +647,94 @@ Return non-nil if a new tarball was created."
(delete-file tarball)
(elpaa--make-one-package pkg-spec tarball))))
+(defun elpaa--string-width (str)
+ "Determine string width in pixels of STR."
+ (let ((output (shell-command-to-string
+ (format "convert -debug annotate xc: -font DejaVu-Sans\
+ -pointsize 110 -annotate 0 %s null: 2>&1"
+ (shell-quote-argument str)))))
+ (save-match-data
+ (if (string-match
+ "Metrics:.*?width: \\([0-9]+\\)"
+ output)
+ (string-to-number (match-string 1 output))
+ (error "Could not determine string width")))))
+
+(defun elpaa--make-badge (file left right)
+ "Make badge svg FILE with LEFT and RIGHT string."
+ (let* ((lw (elpaa--string-width left))
+ (rw (elpaa--string-width right))
+ (pad (elpaa--string-width "x"))
+ (color "#bb3955")
+ (width (/ (+ lw rw (* 4 pad)) 10))
+ (offset -10) ;; Small alignment correction
+ (ctx `((offset . ,offset)
+ (left . ,left)
+ (right . ,right)
+ (lw . ,lw)
+ (rw . ,rw)
+ (width . ,width)
+ (color . ,color)
+ (pad . ,pad))))
+ (with-temp-buffer
+ (insert
+ (replace-regexp-in-string
+ "[ \t\n]+" " "
+ (replace-regexp-in-string
+ "{\\([^}]+\\)}"
+ (lambda (str)
+ (format "%s" (eval (read (match-string 1 str)) ctx)))
+ (replace-regexp-in-string
+ "'" "\""
+ "<?xml version='1.0'?>
+<svg xmlns='http://www.w3.org/2000/svg'
+ xmlns:xlink='http://www.w3.org/1999/xlink'
+ width='{width}'
+ height='20'
+ role='img'
+ aria-label='{left}: {right}'>
+ <title>{left}: {right}</title>
+ <linearGradient id='s' x2='0' y2='100%'>
+ <stop offset='0' stop-color='#bbb' stop-opacity='.1'/>
+ <stop offset='1' stop-opacity='.1'/>
+ </linearGradient>
+ <clipPath id='r'>
+ <rect width='{width}' height='20' rx='3' fill='#fff'/>
+ </clipPath>
+ <g clip-path='url(#r)'>
+ <rect width='{(/ (+ lw (* 2 pad)) 10)}'
+ height='20' fill='#555'/>
+ <rect x='{(1- (/ (+ lw (* 2 pad)) 10))}'
+ width='{width}' height='20' fill='{color}'/>
+ <rect width='{width}' height='20' fill='url(#s)'/>
+ </g>
+ <g fill='#fff'
+ text-anchor='middle'
+ font-family='Verdana,Geneva,DejaVu Sans,sans-serif'
+ font-size='110'
+ text-rendering='geometricPrecision'>
+ <text aria-hidden='true'
+ x='{(+ (/ lw 2) pad offset)}'
+ y='150'
+ fill='#010101' fill-opacity='.3'
+ transform='scale(.1)' textLength='{lw}'>{left}</text>
+ <text x='{(+ (/ lw 2) pad offset)}'
+ y='140' transform='scale(.1)'
+ fill='#fff'
+ textLength='{lw}'>{left}</text>
+ <text aria-hidden='true'
+ x='{(+ lw (/ rw 2) (* 3 pad) offset)}'
+ y='150'
+ fill='#010101' fill-opacity='.3'
+ transform='scale(.1)' textLength='{rw}'>{right}</text>
+ <text x='{(+ lw (/ rw 2) (* 3 pad) offset)}'
+ y='140'
+ transform='scale(.1)'
+ fill='#fff' textLength='{rw}'>{right}</text>
+ </g>
+</svg>"))))
+ (write-region (point-min) (point-max) file))))
+
(defun elpaa--make-one-package (pkg-spec &optional one-tarball)
"Build the new tarballs (if needed) for PKG-SPEC.
If ONE-TARBALL is non-nil, don't try and select some other revision and
@@ -679,6 +767,8 @@ place the resulting tarball into the file named
ONE-TARBALL."
(devel-vers
(concat vers (if (string-match "[0-9]\\'" vers) ".")
"0." date-version))
+ (release-badge (format "%s/%s.svg" elpaa--release-subdir pkgname))
+ (devel-badge (format "%s/%s.svg" elpaa--devel-subdir pkgname))
(tarball (or one-tarball
(concat elpaa--devel-subdir
(format "%s-%s.tar" pkgname devel-vers))))
@@ -725,7 +815,20 @@ place the resulting tarball into the file named
ONE-TARBALL."
(elpaa--get-release-revision
dir pkg-spec vers
(plist-get (cdr pkg-spec) :version-map))))
- (elpaa--release-email pkg-spec metadata dir)))))))))
+ (elpaa--make-badge release-badge
+ (format "%s ELPA" elpaa--name)
+ (format "%s %s" pkgname vers))
+ (elpaa--release-email pkg-spec metadata dir)))))
+
+ ;; Generate missing badges
+ (unless (and (not new) (file-exists-p devel-badge))
+ (elpaa--make-badge devel-badge
+ (format "%s-devel ELPA" elpaa--name)
+ (format "%s %s" pkgname devel-vers)))
+ (unless (file-exists-p release-badge)
+ (elpaa--make-badge release-badge
+ (format "%s ELPA" elpaa--name)
+ (format "%s %s" pkgname vers)))))))
(defun elpaa--call (destination program &rest args)
"Like ‘call-process’ for PROGRAM, DESTINATION, ARGS.
@@ -1143,6 +1246,7 @@ Rename DIR/ to PKG-VERS/, and return the descriptor."
pkg-spec
(or (cdr (assoc :url (aref (cdr pkg) 4)))
(elpaa--get-prop "URL" name srcdir mainsrcfile)))
+ (insert (format "<dt>Badge</dt><dd><img src=\"%s.svg\"/></dd>\n"
(elpaa--html-quote name)))
(insert "</dl>")
(insert (format "<p>To install this package, run in Emacs:</p>
<pre>M-x <span class=\"kw\">package-install</span> RET
<span class=\"kw\">%s</span> RET</pre>"
- [nongnu] elpa-admin 9e01d93 406/439: * elpa-admin.el (elpaa--prune-old-tarballs): Return resulting oldtarballs, (continued)
- [nongnu] elpa-admin 9e01d93 406/439: * elpa-admin.el (elpaa--prune-old-tarballs): Return resulting oldtarballs, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin fae2e2e 412/439: * elpa-admin.el (elpaa--prune-old-tarballs): Fix computation of .sig name, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 0783750 417/439: * elpa-admin.el (elpaa--sandbox-extra-ro-dirs): New var, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin d10026f 419/439: * elpa-admin.el: Preserve release tarballs at least 2 years, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 97ebbd5 405/439: * elpa-admin.el (elpaa--prune-old-tarballs): "(Re)move" the non-kept files, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 8ed7b88 354/439: Rename vars and functions with `elpaa-` prefix, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin d8903b6 358/439: * elpa-admin.el: Add some of the support needed to build Org packages, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 7e5b75b 359/439: * elpa-admin.el: Add support for checking copyright notices, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin c26df96 392/439: * elpa-admin.el: Allow `:doc` to specify several doc files, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 396a74b 421/439: Bump license for package pages to CC BY-ND 4.0, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin c29da22 424/439: * elpa-admin.el: Generate SVG badges,
Philip Kaludercic <=
- [nongnu] elpa-admin fa18a66 413/439: * elpa-admin.el: Improve doc build for the :core packages, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin de2fd22 418/439: * elpa-admin.el (elpaa-read-config): Allow lists of strings, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin e3683d9 426/439: elpa-admin.el: Improve the badge generation code, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 8e351cc 425/439: * elpa-admin.el (elpaa--string-width): Use `elpaa--call`, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin e850286 428/439: Merge branch 'elpa-admin' of git+ssh://git.sv.gnu.org/srv/git/emacs/elpa into elpa-admin, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 6b5c39d 423/439: ; * elpa-admin.el (elpaa--html-footer): Fix LibreJS support., Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 4541ebe 430/439: * elpa-admin.el (elpaa--get-release-revision): Workaround for git bug, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 1beeffd 433/439: * elpa-admin.el (elpaa--make-one-tarball): Return nil on error!, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 005c37e 434/439: * README (Configuration (elpa-config)): Document `elpa-config`, Philip Kaludercic, 2021/10/17
- [nongnu] elpa-admin 97d2765 436/439: * elpa-admin.el (ignore-error): Add backward compatibility definition, Philip Kaludercic, 2021/10/17