Use metas instead of tags for title and published

This commit is contained in:
Jeremy Dormitzer 2019-06-09 13:18:52 -04:00
parent 9afcb7cec8
commit e99a3ba3ba
4 changed files with 22 additions and 17 deletions

View File

@ -1,9 +1,9 @@
#lang pollen #lang pollen
title{A DSL for Music} (define-meta title "A DSL for Music")
published-date[2018 8 5] (define-meta published "2018-08-05")
section{Haskell School of Music} heading{Haskell School of Music}
I recently discovered Haskell School of Music. Its a book about algorithmic music, which is awesome because: a) Ive been obsessed with procedural generation for years and b) I like music as much as I like programming. So you can imagine my excitement when I discovered that someone had written a textbook combining my favorite areas of study. I recently discovered Haskell School of Music. Its a book about algorithmic music, which is awesome because: a) Ive been obsessed with procedural generation for years and b) I like music as much as I like programming. So you can imagine my excitement when I discovered that someone had written a textbook combining my favorite areas of study.
@ -13,7 +13,7 @@ I like Haskell, but I want to write music in Clojure. Why? First of all, because
Before we can explore what a DSL for music would look like, we need to understand how HSoM represents music as data. Before we can explore what a DSL for music would look like, we need to understand how HSoM represents music as data.
section{Music as data} heading{Music as data}
HSoM breaks music down into its component pieces. It represents music using Haskell data structures: HSoM breaks music down into its component pieces. It represents music using Haskell data structures:
@ -49,7 +49,7 @@ But as powerful as this data type is, I wouldnt call it a domain-specific lan
Heres where Clojure comes in. Heres where Clojure comes in.
section{A DSL for music with Clojure} heading{A DSL for music with Clojure}
What would a domain-specific language for music look like in Clojure? I found inspiration in the HTML templating library link[#:href "https://github.com/weavejester/hiccup"]{Hiccup}. Hiccup represents HTML documents (a graph of complex nested nodes, just like music values) using Clojure vectors, like so: What would a domain-specific language for music look like in Clojure? I found inspiration in the HTML templating library link[#:href "https://github.com/weavejester/hiccup"]{Hiccup}. Hiccup represents HTML documents (a graph of complex nested nodes, just like music values) using Clojure vectors, like so:
@ -127,7 +127,7 @@ Furthermore, because Clojure is dynamically typed and supports ◊link[#:href "h
Like the Hiccup vectors, our music vectors blur the boundary between a DSL and a data structure. The vectors are expressive enough to represent any musical concept, but can still be passed around and operated on by normal Clojure functions. As an added advantage, the vectors look similar enough to the HSoM data structures that I can easily follow along with the textbook using Clojure and Overtone. Like the Hiccup vectors, our music vectors blur the boundary between a DSL and a data structure. The vectors are expressive enough to represent any musical concept, but can still be passed around and operated on by normal Clojure functions. As an added advantage, the vectors look similar enough to the HSoM data structures that I can easily follow along with the textbook using Clojure and Overtone.
section{What's next} heading{What's next}
So I have a way to represent music in Clojure now. Whats next? Haskell School of Music ships with a library called Euterpea that knows how to turn the Music data structure into actual sound. So the next step for me is probably porting something like that to Clojure. Im hoping to offload most of that work to Overtone. After that, Ill explore algorithmic composition using the techniques outlined in HSoM. Stay tuned! So I have a way to represent music in Clojure now. Whats next? Haskell School of Music ships with a library called Euterpea that knows how to turn the Music data structure into actual sound. So the next step for me is probably porting something like that to Clojure. Im hoping to offload most of that work to Overtone. After that, Ill explore algorithmic composition using the techniques outlined in HSoM. Stay tuned!

View File

@ -14,9 +14,10 @@
(define (get-posts) (define (get-posts)
(children 'blog)) (children 'blog))
title{}
for/splice[((post (get-posts)))]{ for/splice[((post (get-posts)))]{
let[((src (get-source (path->string (path->complete-path (symbol->string post))))))]{ let[((src (get-source (path->string (path->complete-path (symbol->string post))))))]{
(string-append "blog/" (symbol->string post)) link[#:href (symbol->string post)]{◊section{◊(select 'h1 src)}}
;link[#:href ◊post]{◊(select 'h1 src)}
} }
} }

View File

@ -1,6 +1,6 @@
#lang pollen #lang pollen
title{Jeremy Dormitzer} (define-meta title "Jeremy Dormitzer")
image[#:class "float-left" #:src "images/jeremy.jpg" #:height "512px"] image[#:class "float-left" #:src "images/jeremy.jpg" #:height "512px"]

View File

@ -1,12 +1,16 @@
#lang racket #lang racket
(require pollen/decode txexpr gregor) (require pollen/core pollen/decode txexpr gregor)
(provide (all-defined-out)) (provide (all-defined-out))
(define (root . elements) (define (root . elements)
(txexpr 'div (let ((the-title (select-from-metas 'title (current-metas)))
'((class "content")) (published (select-from-metas 'published (current-metas))))
(decode-elements elements (txexpr 'div
#:txexpr-elements-proc decode-paragraphs))) '((class "content"))
`(,(when/splice the-title (title the-title))
,(when/splice published (published-date published))
,@(decode-elements elements
#:txexpr-elements-proc decode-paragraphs)))))
(define (zip-kws kws kw-args) (define (zip-kws kws kw-args)
(map list (map string->symbol (map keyword->string kws)) kw-args)) (map list (map string->symbol (map keyword->string kws)) kw-args))
@ -22,7 +26,7 @@
(lambda (kws kw-args . elements) (lambda (kws kw-args . elements)
(txexpr 'h1 (zip-kws kws kw-args) elements)))) (txexpr 'h1 (zip-kws kws kw-args) elements))))
(define section (define heading
(make-keyword-procedure (make-keyword-procedure
(lambda (kws kw-args . elements) (lambda (kws kw-args . elements)
(txexpr 'h2 (with-class (zip-kws kws kw-args) "section-header") elements)))) (txexpr 'h2 (with-class (zip-kws kws kw-args) "section-header") elements))))
@ -51,7 +55,7 @@
;; TODO make these links to an index page for each tag ;; TODO make these links to an index page for each tag
(txexpr 'span '((class "tags")) `("Tagged " ,(string-join taglist ", ")))) (txexpr 'span '((class "tags")) `("Tagged " ,(string-join taglist ", "))))
(define (published-date year month day) (define (published-date date-str)
(let ((publish-date (date year month day))) (let ((publish-date (iso8601->date date-str)))
(txexpr (txexpr
'span '((class "published-date")) `("Posted on " ,(~t publish-date "MMMM d, y"))))) 'span '((class "published-date")) `("Posted on " ,(~t publish-date "MMMM d, y")))))