unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#37010] website: export package list to JSON
@ 2019-08-12 14:51 Nicolò Balzarotti
  2019-08-12 15:12 ` [bug#37010] Fix field exported as lists Nicolò Balzarotti
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolò Balzarotti @ 2019-08-12 14:51 UTC (permalink / raw)
  To: 37010


[-- Attachment #1.1: Type: text/plain, Size: 416 bytes --]

Hi,

I'm sending a patch to guix-artwork. My aim was to help in getting this
issue (https://github.com/repology/repology/issues/218) fixed (and have
guix packages back on repology).

Probably is possible to add more fields, but they are not strictly required
(as per https://repology.org/addrepo)

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

Thanks, Nicolò

[-- Attachment #1.2: Type: text/html, Size: 658 bytes --]

[-- Attachment #2: 0001-website-export-JSON-package-list-to-packages.json.patch --]
[-- Type: text/x-patch, Size: 1904 bytes --]

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(+)

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#37010] Fix field exported as lists
  2019-08-12 14:51 [bug#37010] website: export package list to JSON Nicolò Balzarotti
@ 2019-08-12 15:12 ` Nicolò Balzarotti
  2019-08-21 22:24   ` bug#37010: " Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolò Balzarotti @ 2019-08-12 15:12 UTC (permalink / raw)
  To: 37010


[-- Attachment #1.1: Type: text/plain, Size: 139 bytes --]

Hello,

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

Nicolò

[-- Attachment #1.2: Type: text/html, Size: 223 bytes --]

[-- Attachment #2: 0001-website-export-JSON-package-list-to-packages.json.patch --]
[-- Type: text/x-patch, Size: 1912 bytes --]

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#37010: Fix field exported as lists
  2019-08-12 15:12 ` [bug#37010] Fix field exported as lists Nicolò Balzarotti
@ 2019-08-21 22:24   ` Ricardo Wurmus
  2019-08-22  7:14     ` [bug#37010] " Nicolò Balzarotti
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Wurmus @ 2019-08-21 22:24 UTC (permalink / raw)
  To: anothersms; +Cc: 37010-done


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#37010] Fix field exported as lists
  2019-08-21 22:24   ` bug#37010: " Ricardo Wurmus
@ 2019-08-22  7:14     ` Nicolò Balzarotti
  2019-08-22  7:34       ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolò Balzarotti @ 2019-08-22  7:14 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: 37010-done

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

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
>
>

[-- Attachment #2: Type: text/html, Size: 1090 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#37010] Fix field exported as lists
  2019-08-22  7:14     ` [bug#37010] " Nicolò Balzarotti
@ 2019-08-22  7:34       ` Ricardo Wurmus
  0 siblings, 0 replies; 5+ messages in thread
From: Ricardo Wurmus @ 2019-08-22  7:34 UTC (permalink / raw)
  To: Nicolò Balzarotti; +Cc: 37010-done


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!

-- 
Ricardo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-22  7:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 14:51 [bug#37010] website: export package list to JSON Nicolò Balzarotti
2019-08-12 15:12 ` [bug#37010] Fix field exported as lists Nicolò Balzarotti
2019-08-21 22:24   ` bug#37010: " Ricardo Wurmus
2019-08-22  7:14     ` [bug#37010] " Nicolò Balzarotti
2019-08-22  7:34       ` Ricardo Wurmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).