diff mbox series

[bug#37010] Fix field exported as lists

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

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ò

Comments

Ricardo Wurmus Aug. 21, 2019, 10:24 p.m. UTC | #1
Hi Nicolò,

thank you for the patch!

Commit 9c6f714305460e99c681d9b7f368e13bfe49fdd9 is the result of basing
this patch on top of changes to remove GUIX_WEB_SITE_INFO and adjusting
the code so that the site can be built.

I had to convert the package list to a vector, because that’s what Guile
JSON version 3 expects to work with.

I also simplified the code a bit, changed tabs to spaces, and wrote a
commit message.

Thanks again!

--
Ricardo
Nicolò Balzarotti Aug. 22, 2019, 7:14 a.m. UTC | #2
Whops, you had to do lot of things, I'm sorry!

I'll try to do better next time.

Thanks, Nicolò

Il giorno mer 21 ago 2019 alle ore 22:24 Ricardo Wurmus <rekado@elephly.net>
ha scritto:

>
> Hi Nicolò,
>
> thank you for the patch!
>
> Commit 9c6f714305460e99c681d9b7f368e13bfe49fdd9 is the result of basing
> this patch on top of changes to remove GUIX_WEB_SITE_INFO and adjusting
> the code so that the site can be built.
>
> I had to convert the package list to a vector, because that’s what Guile
> JSON version 3 expects to work with.
>
> I also simplified the code a bit, changed tabs to spaces, and wrote a
> commit message.
>
> Thanks again!
>
> --
> Ricardo
>
>
Ricardo Wurmus Aug. 22, 2019, 7:34 a.m. UTC | #3
Hey Nicolò,

> Whops, you had to do lot of things, I'm sorry!

No worries!  I only adjusted your patch, and I didn’t have to think much
about where to add things.  Thanks for getting it started!
diff mbox series

Patch

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