website: export package list to JSON

  • Done
  • quality assurance status badge
Details
2 participants
  • Nicolò Balzarotti
  • Ricardo Wurmus
Owner
unassigned
Submitted by
Nicolò Balzarotti
Severity
normal
N
N
Nicolò Balzarotti wrote on 12 Aug 2019 16:51
(address . guix-patches@gnu.org)
CAO7Ox=Z725rb4jmv01Xbd2g1KV0OpVN5yc6eRbzxENmPqYR0gw@mail.gmail.com
Hi,

I'm sending a patch to guix-artwork. My aim was to help in getting this
guix packages back on repology).

Probably is possible to add more fields, but they are not strictly required

Also, I don't know if (ab)using make-page that way is right. Any suggestion
is welcome.

Thanks, Nicolò
Attachment: file
From 3949a27b653f25704ad57e95133ec9487bcd3ccb 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(+)

Toggle diff (49 lines)
diff --git a/website/apps/packages/builder.scm b/website/apps/packages/builder.scm
index 59f86c1..fc08d6a 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
N
N
Nicolò Balzarotti wrote on 12 Aug 2019 17:12
Fix field exported as lists
(address . 37010@debbugs.gnu.org)
CAO7Ox=Ybw9EShMpxL-Q_vu1WYbpFZa4d5NW+Q6gHXAdcNUZ+Mg@mail.gmail.com
Hello,

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

Nicolò
Attachment: file
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(+)

Toggle diff (49 lines)
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
R
R
Ricardo Wurmus wrote on 22 Aug 2019 00:24
(address . anothersms@gmail.com)(address . 37010-done@debbugs.gnu.org)
87ftlukvht.fsf@elephly.net
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
Closed
N
N
Nicolò Balzarotti wrote on 22 Aug 2019 09:14
(name . Ricardo Wurmus)(address . rekado@elephly.net)(address . 37010-done@debbugs.gnu.org)
CAO7Ox=bHwUyCxg6fk5St5wW52UfE5bUf7EQgc26NABHdcRcW7A@mail.gmail.com
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:

Toggle quote (21 lines)
>
> 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
>
>
Attachment: file
Closed
R
R
Ricardo Wurmus wrote on 22 Aug 2019 09:34
(name . Nicolò Balzarotti)(address . anothersms@gmail.com)(address . 37010-done@debbugs.gnu.org)
87d0gxlklk.fsf@elephly.net
Hey Nicolò,

Toggle quote (2 lines)
> 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!

--
Ricardo
Closed
?