[PATCH] website: Don't append version to URL if latest

  • Open
  • quality assurance status badge
Details
2 participants
  • Alexandros Theodotou
  • Luis Felipe
Owner
unassigned
Submitted by
Alexandros Theodotou
Severity
normal
A
A
Alexandros Theodotou wrote on 28 Mar 2020 00:54
(name . Guix patches)(address . guix-patches@gnu.org)
10fd7f79c9a8d6d6510b7cfcec6b9b96640aff28.camel@zrythm.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-----


L
L
Luis Felipe wrote on 19 Nov 2022 22:55
(name . 40266@debbugs.gnu.org)(address . 40266@debbugs.gnu.org)
aoyJXuy7DeI0THnFgcEYYOUt9V6VGX1u2CrAL3UUNrA3EdQ8ERaPhJQWaAa-dPLoFenHkz91UdPzb84Ijhyx7GJC4VjGV8w2CLtOAqIC4A4=@protonmail.com
Hi Alexandros,

The new https://packages.guix.gnu.org/serves package pages without the version number now. For example:


Sorry to have let your patch go to waste :(
Attachment: signature.asc
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 40266@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 40266
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch