30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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
series-noun ; Retrieve noun-singular from current 'series meta, or ""
attr-present? ; Test if an attribute is present
disposition-values
ymd->english
ymd->dateformat
default-authorname
default-title
tx-strs
|
>
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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
series-noun ; Retrieve noun-singular from current 'series meta, or ""
series-title ; Retrieve title of series in current 'series meta, or ""
attr-present? ; Test if an attribute is present
disposition-values
ymd->english
ymd->dateformat
default-authorname
default-title
tx-strs
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
(define (series-noun)
(define series-pagenode (->pagenode (or (select-from-metas 'series (current-metas)) "")))
(case series-pagenode
['|| ""] ; no series specified
[else (or (select-from-metas 'noun-singular series-pagenode) "")]))
(define (attr-present? name attrs)
(for/or ([attr-pair (in-list attrs)])
(equal? name (car attr-pair))))
(define (maybe-attr name attrs [missing ""])
(define result (assoc name attrs))
(cond
|
>
>
>
>
>
>
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
(define (series-noun)
(define series-pagenode (->pagenode (or (select-from-metas 'series (current-metas)) "")))
(case series-pagenode
['|| ""] ; no series specified
[else (or (select-from-metas 'noun-singular series-pagenode) "")]))
(define (series-title)
(define series-pagenode (->pagenode (or (select-from-metas 'series (current-metas)) "")))
(case series-pagenode
['|| ""] ; no series specified
[else (or (select-from-metas 'title series-pagenode) "")]))
(define (attr-present? name attrs)
(for/or ([attr-pair (in-list attrs)])
(equal? name (car attr-pair))))
(define (maybe-attr name attrs [missing ""])
(define result (assoc name attrs))
(cond
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
(cond [(string=? "" str) (values "" "")]
[else (let ([splut (string-split str)])
(values (car splut) (string-join (cdr splut))))]))
;; The format of a note’s ID is “HTML-driven” (used as an anchor link) but is included
;; here since it also serves as a primary key in the DB.
(define (build-note-id txpr)
(string-append "#"
(maybe-attr 'date (get-attrs txpr))
"_"
(uri-encode (maybe-attr 'author (get-attrs txpr) default-authorname))))
;; Extract the last disposition (if any), and the ID of the disposing note, out of a list of notes
(define (notes->last-disposition-values txprs)
(define (contains-disposition? tx) (attr-present? 'disposition (get-attrs tx)))
(define disp-notes (filter contains-disposition? txprs))
|
<
|
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
(cond [(string=? "" str) (values "" "")]
[else (let ([splut (string-split str)])
(values (car splut) (string-join (cdr splut))))]))
;; The format of a note’s ID is “HTML-driven” (used as an anchor link) but is included
;; here since it also serves as a primary key in the DB.
(define (build-note-id txpr)
(string-append (maybe-attr 'date (get-attrs txpr))
"_"
(uri-encode (maybe-attr 'author (get-attrs txpr) default-authorname))))
;; Extract the last disposition (if any), and the ID of the disposing note, out of a list of notes
(define (notes->last-disposition-values txprs)
(define (contains-disposition? tx) (attr-present? 'disposition (get-attrs tx)))
(define disp-notes (filter contains-disposition? txprs))
|