~aasg/haunted-blog

ref: fef67bdcac88c14b6ac6affe93e290c1a4fb6ee2 haunted-blog/scm/aasg/front-matter/json.scm -rw-r--r-- 621 bytes
fef67bdc — Aluísio Augusto Silva Gonçalves Render post tags and relayout post lists 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(define-module (aasg front-matter json)
               #:use-module (ice-9 rdelim)
               #:use-module (json)
               #:export (read-json-front-matter))

(define (read-json-front-matter port)
  (if (string=? "---" (read-line port))
      (let loop ((lines '()))
        (let ((line (read-line port)))
          (cond
            ((eof-object? line)
             (error "EOF while reading metadata"))
            ((or (string=? "---" line) (string=? "..." line))
                (json-string->scm (string-join (reverse lines) "\n")))
            (else
              (loop (cons line lines))))))
      '()))