unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#40266] [PATCH] website: Don't append version to URL if latest
@ 2020-03-27 23:54 Alexandros Theodotou
  2022-11-19 21:55 ` Luis Felipe via Guix-patches via
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandros Theodotou @ 2020-03-27 23:54 UTC (permalink / raw)
  To: 40266


[-- Attachment #1.1: Type: text/plain, Size: 171 bytes --]

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

[-- Attachment #1.2: 0001-website-Don-t-append-version-to-URL-if-latest.patch --]
[-- Type: text/x-patch, Size: 3196 bytes --]

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(-)

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


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [bug#40266] [PATCH] website: Don't append version to URL if latest
  2020-03-27 23:54 [bug#40266] [PATCH] website: Don't append version to URL if latest Alexandros Theodotou
@ 2022-11-19 21:55 ` Luis Felipe via Guix-patches via
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Felipe via Guix-patches via @ 2022-11-19 21:55 UTC (permalink / raw)
  To: 40266@debbugs.gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 218 bytes --]

Hi Alexandros,

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

https://packages.guix.gnu.org/packages/gobby/

Sorry to have let your patch go to waste :(

[-- Attachment #1.2: publickey - luis.felipe.la@protonmail.com - 0x12DE1598.asc --]
[-- Type: application/pgp-keys, Size: 1722 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-19 21:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 23:54 [bug#40266] [PATCH] website: Don't append version to URL if latest Alexandros Theodotou
2022-11-19 21:55 ` Luis Felipe via Guix-patches via

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).