summaryrefslogtreecommitdiff
path: root/website/www
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-12-13 17:22:52 +0100
committerLudovic Courtès <ludo@gnu.org>2016-12-13 17:22:52 +0100
commit3ef3b0445241df1dc47c3717e63ffcf6267b3c70 (patch)
tree17462f93a2fc89d4eb81cb2f5c433aef4e6fb351 /website/www
parent5c3c1981841db3b50ec2be5a70b6babf76494722 (diff)
downloadguix-artwork-3ef3b0445241df1dc47c3717e63ffcf6267b3c70.tar
guix-artwork-3ef3b0445241df1dc47c3717e63ffcf6267b3c70.tar.gz
website: Add procedure to generate 'packages.json'.
* website/www/packages.scm (packages->json): New procedure. * website/README: Mention Guile-JSON.
Diffstat (limited to 'website/www')
-rw-r--r--website/www/packages.scm19
1 files changed, 18 insertions, 1 deletions
diff --git a/website/www/packages.scm b/website/www/packages.scm
index d050a03..55d494e 100644
--- a/website/www/packages.scm
+++ b/website/www/packages.scm
@@ -34,6 +34,7 @@
#:use-module (gnu packages)
#:use-module (sxml simple)
#:use-module (sxml fold)
+ #:use-module (json)
#:use-module (web uri)
#:use-module (ice-9 match)
#:use-module (ice-9 vlist)
@@ -47,7 +48,8 @@
#:export (%groups
package-pages
paginated-packages-page
- issues-page))
+ issues-page
+ packages->json))
(define lookup-gnu-package
(let ((gnu (delay (official-gnu-packages))))
@@ -332,6 +334,21 @@ of the form \"PACKAGE-X.Y.Z\"."
(id "top"))
"^")))
+(define* (packages->json #:optional (packages (all-packages)))
+ "Return a JSON string representing PACKAGES."
+ (define (package->alist package)
+ `((name . ,(package-name package))
+ (version . ,(package-version package))
+ (cpe-name . ,(or (assoc-ref (package-properties package) 'cpe-name)
+ (package-name package)))
+ (cpe-version . ,(or (assoc-ref (package-properties package)
+ 'cpe-version)
+ (package-version package)))
+ (home-page . ,(package-home-page package))))
+
+ (scm->json-string (map package->alist packages)
+ #:pretty #t))
+
(define (number* number)
"Return NUMBER correctly formatting according to English conventions."
(number->locale-string number 0