@@ -10,24 +10,28 @@ net/uri-codec file/sha1 gregor txexpr racket/list + racket/match + racket/port racket/system racket/string) ;; 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-source-path here-id listing-context series-metas-noun ; Retrieve noun-singular from current 'series meta, or "" series-metas-title ; Retrieve title of series in current 'series meta, or "" metas-series-pagenode invalidate-series + checked-in? make-tag-predicate tx-strs ymd->english ymd->dateformat default-authorname @@ -55,20 +59,25 @@ (define (maybe-meta m [missing ""]) (cond [(current-metas) (or (select-from-metas m (current-metas)) missing)] [else missing])) +;; Return the current source path, relative to (current-project-root) +(define (here-source-path) + (match (current-metas) + [(? hash? m) + (define-values (_ rel-path-parts) + (drop-common-prefix (explode-path (current-project-root)) + (explode-path (string->path (hash-ref m 'here-path))))) + (apply build-path rel-path-parts)] + [_ (string->path ".")])) + ;; 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 (string->path ".")])) + (->output-path (here-source-path))) (define listing-context (make-parameter "")) ;; Checks current-metas for a 'series meta and returns the pagenode of that series, ;; or '|| if no series is specified. @@ -117,10 +126,20 @@ (format "~a.poly.pm" series-name))) (when (file-exists? series-file) (case (system-type 'os) [(windows) (system (format "type nul >> ~a" series-file))] [else (system (format "touch ~a" series-file))])))) + +;; Determine if the current article has been checked into Fossil repo +(define (checked-in?) + (cond [(current-metas) + (define articles-path (build-path (current-project-root) articles-folder)) + (define checked-in + (with-output-to-string + (lambda () (system (format "/usr/local/bin/fossil ls ~a" articles-path))))) + (string-contains? checked-in (path->string (here-source-path)))] + [else #f])) ;; ~~~ Project-wide Pagetrees ~~~ (define (include-in-pagetree folder extension) (define (matching-file? f)