26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
+
|
articles
articles+notes
listing-htmls
<listing-full>
<listing-excerpt>
<listing-short>
unfence
preheat-series!
series-grouped-list)
;; Cache DB and Schemas
(define DBFILE (build-path (current-project-root) "vitreous.sqlite"))
(define cache-conn (sqlite3-connect #:database DBFILE #:mode 'create))
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
-
+
|
(define (s->p x) (format "~a/~a.html" series-folder x))
(match s
[(list series ...)
(where q (in a.series-page ,(map s->p series)))] ; WHERE series-page IN (item1 ...)
[(or (? string? series) (? symbol? series))
(where q (= a.series-page ,(s->p series)))] ; WHERE series-page = "item"
[#t
(where q (= a.series-page ,(path->string (here-output-path))))]
(where q (like a.series-page ,(format "%~a" (here-output-path))))]
[_ q]))
;; (Private use) Convenience for the WHERE `conceal` NOT LIKE clause
(define (where-not-concealed q)
(define base-clause (where q (not (like a.conceal "%all%"))))
(match (listing-context)
["" base-clause]
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
;; ^^^^^
(define (<listing-excerpt> query-func #:series [s #t] #:limit [lim -1] #:order [ord 'desc])
`(style ,@(listing-htmls (query-func 'excerpt #:series s #:limit lim #:order ord))))
;; ^^^^^^^^
(define (<listing-short> query-func #:series [s #t] #:limit [lim -1] #:order [ord 'desc])
`(style "<ul class=\"article-list\">"
,@(listing-htmls (query-func 'short #:series s #:limit lim #:order ord))
"</ul>")) ;; ^^^^^^
`(style ,@(listing-htmls (query-func 'short #:series s #:limit lim #:order ord))))
;; ^^^^^^
;; Remove "<style>" and "</style>" introduced by using ->html on docs containing output from
;; listing functions
(define (unfence html-str)
(regexp-replace* #px"<[\\/]{0,1}style>" html-str ""))
;;
;; ~~~ Fetching series ~~~
;;
(define (series-grouped-list)
(~> (for/list ([row (in-entities cache-conn (from cache:series #:as s))]) row)
(group-list-by cache:series-noun-plural _ string-ci=?)))
;; Preloads the SQLite cache with info about each series.
;; I may not actually need this but I’m leaving it for now.
(define (preheat-series!)
(query-exec cache-conn
(~> (from cache:series #:as s)
(where 1)
delete))
(define series-rows
(for/list ([series-pagenode (in-list (cdr (series-pagetree)))])
(define series-metas (get-metas series-pagenode))
(make-cache:series
#:page series-pagenode
#:title (hash-ref series-metas 'title)
#:published (hash-ref series-metas 'published "")
#:noun-plural (hash-ref series-metas 'noun-plural "")
#:noun-singular (hash-ref series-metas 'noun-singular ""))))
(void (apply insert! cache-conn series-rows)))
|