~aasg/haunted-blog

ref: ddc39469a1b6ea301e20815b2cedc4491472c9df haunted-blog/scm/aasg/front-matter/json.scm -rw-r--r-- 751 bytes
ddc39469 — Aluísio Augusto Silva Gonçalves Apply SPDX copyright and license headers in compliance with REUSE 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
; SPDX-FileCopyrightText: 2020 Aluísio Augusto Silva Gonçalves <https://aasg.name>
; SPDX-License-Identifier: GPL-3.0-or-later

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