From patchwork Fri Mar 27 23:54:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandros Theodotou X-Patchwork-Id: 20918 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F3C7A27BBE4; Fri, 27 Mar 2020 23:56:09 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 5B25227BBEA for ; Fri, 27 Mar 2020 23:56:09 +0000 (GMT) Received: from localhost ([::1]:48362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHypc-00085G-S4 for patchwork@mira.cbaines.net; Fri, 27 Mar 2020 19:56:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34428) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHypX-00083T-F4 for guix-patches@gnu.org; Fri, 27 Mar 2020 19:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHypW-0002hs-8w for guix-patches@gnu.org; Fri, 27 Mar 2020 19:56:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55792) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHypW-0002ho-62 for guix-patches@gnu.org; Fri, 27 Mar 2020 19:56:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jHypW-0008Py-4l for guix-patches@gnu.org; Fri, 27 Mar 2020 19:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40266] [PATCH] website: Don't append version to URL if latest Resent-From: Alexandros Theodotou Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 27 Mar 2020 23:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40266 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40266@debbugs.gnu.org X-Debbugs-Original-To: Guix patches Received: via spool by submit@debbugs.gnu.org id=B.158535333932320 (code B ref -1); Fri, 27 Mar 2020 23:56:01 +0000 Received: (at submit) by debbugs.gnu.org; 27 Mar 2020 23:55:39 +0000 Received: from localhost ([127.0.0.1]:33532 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHyp8-0008PE-Vz for submit@debbugs.gnu.org; Fri, 27 Mar 2020 19:55:39 -0400 Received: from lists.gnu.org ([209.51.188.17]:35532) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHyp6-0008P6-Lg for submit@debbugs.gnu.org; Fri, 27 Mar 2020 19:55:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34397) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHyp5-0007p0-5o for guix-patches@gnu.org; Fri, 27 Mar 2020 19:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHyp3-0002Ph-8n for guix-patches@gnu.org; Fri, 27 Mar 2020 19:55:34 -0400 Received: from mout02.posteo.de ([185.67.36.142]:43869) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHyp2-0008Fl-Uw for guix-patches@gnu.org; Fri, 27 Mar 2020 19:55:33 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 63EF42400FB for ; Sat, 28 Mar 2020 00:54:29 +0100 (CET) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 48pzGr2gYSz9rxK for ; Sat, 28 Mar 2020 00:54:27 +0100 (CET) Message-ID: <10fd7f79c9a8d6d6510b7cfcec6b9b96640aff28.camel@zrythm.org> From: Alexandros Theodotou Date: Fri, 27 Mar 2020 23:54:27 +0000 User-Agent: Evolution 3.32.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 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 ;;; Copyright © 2017 Eric Bavier +;;; Copyright © 2020 Alexandros Theodotou ;;; ;;; 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 () + 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 () 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