summaryrefslogtreecommitdiff
path: root/skribe-utils.scm
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2016-01-17 12:53:42 +0100
committerrekado <rekado@elephly.net>2016-01-17 12:53:42 +0100
commit5850869f2637fe8df7f4ec08c9c4a87edec2025f (patch)
tree4c3e2f9902da32280dec4ad6134d9fb2ecebdd83 /skribe-utils.scm
parentb35c977dd898cb92c973fadc38cb2a50f6338832 (diff)
move custom skribe stuff to skribe-utils.scm
Diffstat (limited to 'skribe-utils.scm')
-rw-r--r--skribe-utils.scm62
1 files changed, 62 insertions, 0 deletions
diff --git a/skribe-utils.scm b/skribe-utils.scm
new file mode 100644
index 0000000..3bdc2d8
--- /dev/null
+++ b/skribe-utils.scm
@@ -0,0 +1,62 @@
+(define-module (skribe-utils)
+ #:use-module (ice-9 match) ; match-lambda
+ #:use-module (srfi srfi-1) ; list stuff
+ #:export (email
+ ~
+ table
+ lyrics
+ ref
+ figure
+ wide-img))
+
+(define (email address)
+ "Obfuscate a given email ADDRESS."
+ `(span (@ (class "obfuscated"))
+ ,(string-map (lambda (c) (integer->char (+ 1 (char->integer c))))
+ address)))
+
+(define (~)
+ "Non-breaking space."
+ (string #\240))
+
+(define* (table #:key (align '()) headers rows)
+ "Build HTML tables more easily."
+ (let ((alignment (append align
+ (make-list (- (length headers)
+ (length align))
+ "left"))))
+ (define (make-row fields)
+ `(tr ,(map (match-lambda
+ ((field alignment)
+ `(td (@ (align ,alignment)) ,field)))
+ (zip fields alignment))))
+ (define (make-header fields)
+ `(tr (@ (class "header"))
+ ,(map (match-lambda
+ ((field alignment)
+ `(th (@ (align ,alignment)) ,field)))
+ (zip fields alignment))))
+ `(table
+ (thead ,(make-header headers))
+ (tbody ,(map make-row rows)))))
+
+(define (lyrics . contents)
+ `(pre (@ (class "lyrics")) ,contents))
+
+(define (ref url text)
+ `(a (@ (href ,url)) ,text))
+
+(define (figure file caption)
+ `(div (@ (class "figure"))
+ (img (@ (src ,(if (string-prefix? "/" file)
+ file
+ (string-append "/images/posts/" file)))
+ (alt ,caption)))
+ (p (@ (class "caption")) ,caption)))
+
+(define (wide-img file alt)
+ `(img (@ (class "full stretch")
+ (src ,(if (string-prefix? "/" file)
+ file
+ (string-append "/images/posts/" file)))
+ (alt ,alt))))