(name . Guix patches)(address . guix-patches@gnu.org)
Hi,
This patch uses /packages/NAME instead of /packages/NAME-VERSION if the
package is the latest version available, so that URLs are future-proof.
Thanks,
Alex
From f960cc51bf594afc4afe86e773a7536369208c8e Mon Sep 17 00:00:00 2001
From: Alexandros Theodotou <alex@zrythm.org>
Date: Fri, 27 Mar 2020 23:49:25 +0000
Subject: [PATCH] website: Don't append version to URL if latest
* website/apps/packages/utils.scm (package-url-path): Return only
package name when the package is the latest available version.
---
website/apps/packages/utils.scm | 54 ++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 5 deletions(-)
Toggle diff (85 lines)
diff --git a/website/apps/packages/utils.scm b/website/apps/packages/utils.scm
index fb9d3cf..9c2456d 100644
--- a/website/apps/packages/utils.scm
+++ b/website/apps/packages/utils.scm
@@ -1,6 +1,7 @@
;;; GNU Guix web site
;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Eric Bavier <bavier@member.fsf.org>
+;;; Copyright © 2020 Alexandros Theodotou <alex@zrythm.org>
;;;
;;; Initially written by sirgazil
;;; who waives all copyright interest on this file.
@@ -30,6 +31,7 @@
#:use-module (guix build utils)
#:use-module (guix build download)
#:use-module (guix download)
+ #:use-module (semver)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (texinfo)
@@ -223,15 +225,57 @@ vocabulary."
patches))
+(define (package-is-latest-ver? package)
+ "Return whether the PACKAGE is the latest version available.
+
+ PACKAGE (<package>)
+ A package object as defined in the GNU Guix API reference."
+
+ ;; return whether version string a is newer than b
+ (define (is-newer pkgver-a pkgver-b)
+ (if (and (string->semver pkgver-a)
+ (string->semver pkgver-b))
+ (semver>?
+ (string->semver pkgver-a)
+ (string->semver pkgver-b))
+ (string>? pkgver-a pkgver-b)))
+
+ ;; return packages with same name and different versions
+ (define (get-same-pkgs-with-different-ver pkg)
+ (fold
+ (lambda (x accumulator)
+ (if
+ (and
+ (not (string=? (package-version x)
+ (package-version pkg)))
+ (string=? (package-name x)
+ (package-name pkg)))
+ (cons x accumulator)
+ accumulator))
+ '()
+ (all-packages)))
+
+ (let loop ((x (get-same-pkgs-with-different-ver package)))
+ (cond
+ ((not (pair? x))
+ #t)
+ ((is-newer (package-version (car x))
+ (package-version package))
+ #f)
+ (else
+ (loop (cdr x))))))
+
(define (package-url-path package)
- "Return a URL path for the PACKAGE in the form packages/NAME-VERSION/.
+ "Return a URL path for the PACKAGE in the form packages/NAME-VERSION/
+(or packages/NAME if the package is the latest version).
PACKAGE (<package>)
A package object as defined in the GNU Guix API reference."
- (url-path-join "packages"
- (string-append (package-name package)
- "-"
- (package-version package))))
+ (if (package-is-latest-ver? package)
+ (url-path-join "packages" (package-name package))
+ (url-path-join "packages"
+ (string-append (package-name package)
+ "-" (package-version package)))))
(define (packages/group-by-letter packages)
--
2.26.0
-----BEGIN PGP SIGNATURE-----
iQEzBAABCAAdFiEESBMjhK0999huJUuDAi6uQjE9cPMFAl5+kjMACgkQAi6uQjE9
cPNyzwf+NfsOZ+nxq2mRIyWMOq/txSkHLwDLWd6wwUlm0OJQVR1LKsAJh1ssq8wG
beXnKtyEjfOYfPQbJDKUtCkSpe+zi4AEJLIg4ZK11ohhjo8Zhls3gXCJ6OohvOwN
DU8bbC6aJVMTCm2CNy2YHm/5JrfQwArkK9i4x2L29z0U7LSjVtk5rOERArj7EwCE
TY30Eb5LYHmzNs9z/VZWxkjKmaWfwUE3EcoH12N4Bv74DcLBynTWBjN7Bu64y+Hj
NEnK/G60BFNE6DjBLpZ7xzn2KaXLtcQ0YnRCJQWfUq72IkAM8gbpfAgh1CASCSGM
I80VirlPMNOYL5PH0T7U1u3NPgP/hw==
=Xz3Q
-----END PGP SIGNATURE-----