diff options
author | Kenny Ballou <kballou@devnulllabs.io> | 2020-01-28 21:49:30 -0700 |
---|---|---|
committer | Kenny Ballou <kballou@devnulllabs.io> | 2020-02-05 17:33:12 -0700 |
commit | 0eea4a0abfdbf1225abd148eac0a7f151c1144b3 (patch) | |
tree | 7572d62e5a9260c2b755d6c085769f2dcab5e8b0 /scm | |
parent | 1bb882edd5c1745d1a1bd4cc12e30fcbd8f81be9 (diff) | |
download | kennyballou.com-0eea4a0abfdbf1225abd148eac0a7f151c1144b3.tar.gz kennyballou.com-0eea4a0abfdbf1225abd148eac0a7f151c1144b3.tar.xz |
code-{build,commit} auto build and deploy blog
Create codecommit and codebuild resources to store and build web/blog
content. Add in a lambda function to trigger the builds automatically
to futher automate deployment and publishing of content.
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'scm')
-rwxr-xr-x | scm/ppag.scm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/scm/ppag.scm b/scm/ppag.scm new file mode 100755 index 0000000..e53ca1a --- /dev/null +++ b/scm/ppag.scm @@ -0,0 +1,50 @@ +#!/usr/bin/env sh +exec guile -e '(@ (ppag) main)' -s "${0}" "${@}" +!# +(define-module (ppag)) + +(export main) + +(use-modules (ice-9 match)) +(use-modules (ice-9 pretty-print)) +(use-modules (ice-9 rdelim)) + +(define (read-file filename) + "Read the entire contents of the provided file + +Reads the file line by line, accumulating the result into a list. Stops when +reaching the EOF marker. `cons' will construct the list in reverse, reverse at +the end. + +We assume the file provided exists and is readable." + (define (iter fh acc) + (let ((line (read-line fh))) + (if (eof-object? line) + acc + (iter fh (cons line acc))))) + (let ((fh (open-input-file filename))) + (reverse (iter fh '())))) + +(define (json-encode-line line) + "JSON encode the provided line." + (string-join (append '("\"") (map json-encode-char (string->list line)) '("\"")) "")) + +(define (json-encode-char char) + "JSON encode character + +We need to take special care around quotes and backslack characters." + (cond ((eq? char #\") "\"") + ((eq? char #\\) "\\") + (else + (list->string (list char))))) + +(define (json-encode-file filename) + "JSON encode the file, line by line" + (map json-encode-line (read-file filename))) + +(define (main args) + (match args + ((_ input-file) + (display (string-join (json-encode-file input-file) ",\n")) + (newline)) + (_ (error "Unrecognized usage.")))) |