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

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