@@ -22,10 +22,11 @@ ;; ------------------------------------------------------------------------- (require pollen/core pollen/pagetree pollen/setup + pollen/file net/uri-codec gregor txexpr racket/list racket/string) @@ -32,10 +33,11 @@ ;; Provides common helper functions used throughout the project (provide maybe-meta ; Select from (current-metas) or default value ("") if not available maybe-attr ; Return an attribute’s value or a default ("") if not available + here-output-path series-noun ; Retrieve noun-singular from current 'series meta, or "" series-title ; Retrieve title of series in current 'series meta, or "" series-pagenode make-tag-predicate tx-strs @@ -60,10 +62,21 @@ (define (default-title body-txprs) (format "“~a…”" (first-words body-txprs 5))) (define (maybe-meta m [missing ""]) (or (select-from-metas m (current-metas)) missing)) + +;; Return the current output path, relative to (current-project-root) +;; Similar to the variable 'here' which is only accessible in Pollen templates, +;; except this is an actual path, not a string. +(define (here-output-path) + (cond [(current-metas) + (define-values (_ rel-path-parts) + (drop-common-prefix (explode-path (current-project-root)) + (explode-path (string->path (select-from-metas 'here-path (current-metas)))))) + (->output-path (apply build-path rel-path-parts))] + [else (error "No metas are available")])) ;; Checks current-metas for a 'series meta and returns the pagenode of that series, ;; or '|| if no series is specified. (define (series-pagenode) (define maybe-series (or (select-from-metas 'series (current-metas)) ""))