unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Nicolò Balzarotti" <anothersms@gmail.com>
To: 37010@debbugs.gnu.org
Subject: [bug#37010] website: export package list to JSON
Date: Mon, 12 Aug 2019 14:51:55 +0000	[thread overview]
Message-ID: <CAO7Ox=Z725rb4jmv01Xbd2g1KV0OpVN5yc6eRbzxENmPqYR0gw@mail.gmail.com> (raw)


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


             reply	other threads:[~2019-08-12 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 14:51 Nicolò Balzarotti [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO7Ox=Z725rb4jmv01Xbd2g1KV0OpVN5yc6eRbzxENmPqYR0gw@mail.gmail.com' \
    --to=anothersms@gmail.com \
    --cc=37010@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).