guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/29: website: packages: Implement grouping by letter.


From: Ludovic Courtès
Subject: 05/29: website: packages: Implement grouping by letter.
Date: Wed, 6 Dec 2017 09:24:22 -0500 (EST)

civodul pushed a commit to branch master
in repository guix-artwork.

commit ccc5964a475e6e5b089a29698a6d782998c5239c
Author: Ludovic Courtès <address@hidden>
Date:   Sat Jul 29 17:28:10 2017 +0200

    website: packages: Implement grouping by letter.
    
    * website/apps/packages/utils.scm (packages/group-by-letter): Implement.
---
 website/apps/packages/utils.scm | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/website/apps/packages/utils.scm b/website/apps/packages/utils.scm
index 1a15084..4e435be 100644
--- a/website/apps/packages/utils.scm
+++ b/website/apps/packages/utils.scm
@@ -9,6 +9,7 @@
   #:use-module (apps packages types)
   #:use-module (guix packages)
   #:use-module (guix utils)
+  #:use-module (ice-9 match)
   #:export (location->ilink
            package-build-issues
            package-issues?
@@ -100,8 +101,6 @@
                                (package-version package))))
 
 
-;;; TODO: Dummy. Implement it.
-;;; (https://bitbucket.org/sirgazil/guixsd-website/issues/38/)
 (define (packages/group-by-letter packages)
   "Return a list of alphabetically grouped packages.
 
@@ -111,6 +110,20 @@
   RETURN (list)
     A list of lists of packages where each list corresponds to the
     packages whose name starts with a specific letter."
-  (cond ((null? packages) '())
-       (else
-        (map (lambda (letter) (cons letter packages)) alphabet))))
+  (define (starts-with-digit? package)
+    (char-set-contains? char-set:digit
+                        (string-ref (package-name package) 0)))
+
+  (define (starts-with-letter? letter)
+    (let ((letter (string-downcase letter)))
+      (lambda (package)
+        (string-prefix? letter (package-name package)))))
+
+  (map (lambda (letter)
+         (match letter
+           ("0-9"
+            (cons letter (filter starts-with-digit? packages)))
+           (_
+            (cons letter
+                  (filter (starts-with-letter? letter) packages)))))
+       alphabet))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]