@@ -24,10 +24,11 @@ (require pollen/core pollen/pagetree pollen/setup pollen/file net/uri-codec + file/sha1 gregor txexpr racket/list racket/system racket/string) @@ -35,10 +36,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 + here-id series-noun ; Retrieve noun-singular from current 'series meta, or "" series-title ; Retrieve title of series in current 'series meta, or "" series-pagenode invalidate-series make-tag-predicate @@ -61,11 +63,10 @@ (define series-folder "series") (define articles-folder "articles") (define (default-title body-txprs) (format "“~a…”" (first-words body-txprs 5))) - (define (maybe-meta m [missing ""]) (cond [(current-metas) (or (select-from-metas m (current-metas)) missing)] [else missing])) @@ -98,10 +99,18 @@ (define (series-title) (define series-pnode (series-pagenode)) (case series-pnode ['|| ""] ; no series specified [else (or (select-from-metas 'title series-pnode) "")])) + +;; Generates a short ID for the current article +(define (here-id [suffix #f]) + (define here-hash + (substring (bytes->hex-string (sha1-bytes (path->bytes (here-output-path)))) 0 8)) + (cond [(list? suffix) (apply string-append here-hash suffix)] + [(string? suffix) (string-append here-hash suffix)] + [else here-hash])) ;; “Touches” the last-modified date on the current article’s series, if there is one (define (invalidate-series) (define series-name (maybe-meta 'series #f))