[bug#37010] Fix field exported as lists
diff mbox series

Message ID CAO7Ox=Ybw9EShMpxL-Q_vu1WYbpFZa4d5NW+Q6gHXAdcNUZ+Mg@mail.gmail.com
State New
Headers show
Series
  • [bug#37010] Fix field exported as lists
Related show

Commit Message

Nicolò Balzarotti Aug. 12, 2019, 3:12 p.m. UTC
Hello,

Sorry, I just realized fields were exported as a single-element lists.
Fixed now, please ignore the previous patch.

Nicolò

Patch
diff mbox series

From 88d1951d62b59a7458150a466d77b790f13343ea Mon Sep 17 00:00:00 2001
From: nixo <nicolo@nixo.xyz>
Date: Mon, 12 Aug 2019 16:42:08 +0200
Subject: [PATCH] website: export JSON package list to packages.json

---
 website/apps/packages/builder.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/website/apps/packages/builder.scm b/website/apps/packages/builder.scm
index 59f86c1..58a6a64 100644
--- a/website/apps/packages/builder.scm
+++ b/website/apps/packages/builder.scm
@@ -1,6 +1,7 @@ 
 ;;; GNU Guix web site
 ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2019 Nicolò Balzarotti <nicolo@nixo.xyz>
 ;;;
 ;;; Initially written by sirgazil
 ;;; who waives all copyright interest on this file.
@@ -36,6 +37,8 @@ 
   #:use-module (haunt page)
   #:use-module (haunt utils)
   #:use-module (srfi srfi-1)
+  #:use-module (guix)
+  #:use-module (json)
   #:export (builder))
 
 
@@ -76,6 +79,7 @@ 
        ;; used instead. They should generate pages as those described
        ;; in the proposal.
        (list
+	(package-json-builder)
         (detailed-index-builder)
         (detailed-package-list-builder)))))
 
@@ -101,6 +105,17 @@ 
 			     (length (all-packages))))))
     (make-page "packages/index.html" (index-t context) sxml->html)))
 
+(define (package-json-builder)
+  "Return a JSON listing all packages."
+  (define (package-fields package)
+    `(("name"     . ,(package-name package))
+      ("version"  . ,(package-version package))
+      ("synopsis" . ,(package-synopsis package))
+      ("homepage" . ,(package-home-page package))))
+  (define (packages->json packages)
+    (map package-fields packages))
+  (make-page "packages.json"
+	     (packages->json (all-packages)) scm->json))
 
 (define (detailed-index-builder)
   "Return a Haunt page listing some random packages."
-- 
2.22.0