mirror of
https://gitdab.com/cadence/breezewiki.git
synced 2026-03-05 13:40:27 -05:00
update file page for jsonp
This commit is contained in:
83
lib/make-json.rkt
Normal file
83
lib/make-json.rkt
Normal file
@@ -0,0 +1,83 @@
|
||||
#lang racket/base
|
||||
(require racket/list/grouping
|
||||
racket/match
|
||||
racket/syntax)
|
||||
|
||||
(provide make-json)
|
||||
|
||||
(module+ test
|
||||
(require rackunit json)
|
||||
(define sample
|
||||
`(: continue
|
||||
(: iistart "2022-01-23T03:44:17Z"
|
||||
fucontinue "455"
|
||||
continue "||")
|
||||
query
|
||||
(: pages
|
||||
(: 198
|
||||
(: pageid 198
|
||||
ns 6
|
||||
title "File:Rainbow Flag1.svg"
|
||||
imageinfo
|
||||
((: timestamp "2025-03-10T07:24:50Z"
|
||||
user "DogeMcMeow"))
|
||||
fileusage
|
||||
((: pageid 191
|
||||
ns 0
|
||||
title "Gay")
|
||||
(: pageid 215
|
||||
ns 0
|
||||
title "LGBTQIA+"))))))))
|
||||
|
||||
(define (make-json data)
|
||||
(match data
|
||||
[(list ': kvs ...)
|
||||
(for/fold ([h (hasheq)])
|
||||
([kv (windows 2 2 kvs)])
|
||||
(match-define (list raw-k v) kv)
|
||||
(define k (format-symbol "~a" raw-k))
|
||||
(hash-set h k (make-json v)))]
|
||||
[(list x ...)
|
||||
(map make-json x)]
|
||||
[x
|
||||
x]))
|
||||
|
||||
(module+ test
|
||||
(check-equal? (make-json sample)
|
||||
(string->jsexpr #<<END
|
||||
{
|
||||
"continue": {
|
||||
"iistart": "2022-01-23T03:44:17Z",
|
||||
"fucontinue": "455",
|
||||
"continue": "||"
|
||||
},
|
||||
"query": {
|
||||
"pages": {
|
||||
"198": {
|
||||
"pageid": 198,
|
||||
"ns": 6,
|
||||
"title": "File:Rainbow Flag1.svg",
|
||||
"imageinfo": [
|
||||
{
|
||||
"timestamp": "2025-03-10T07:24:50Z",
|
||||
"user": "DogeMcMeow"
|
||||
}
|
||||
],
|
||||
"fileusage": [
|
||||
{
|
||||
"pageid": 191,
|
||||
"ns": 0,
|
||||
"title": "Gay"
|
||||
},
|
||||
{
|
||||
"pageid": 215,
|
||||
"ns": 0,
|
||||
"title": "LGBTQIA+"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
END
|
||||
)))
|
||||
Reference in New Issue
Block a user