| 
100
101
102
103
104
105
106
107
108
109
110111
112
113
114
115
116
117
118 | 
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 | 
-
-
-
+
+
+
-
+
 | 
  (cond [(non-empty-string? subhead) (add-new-subentry e record)]
        [else (add-entry-link e record)]))
;; Get the index entries from the SQLite cache, return them as a list of vectors (Records!)
(define (fetch-entries)
  (define q
    ◊string-append{
 SELECT entry, subentry, a.rowid, "◊web-root" || k.pageSELECT entry, subentry, a.rowid, "◊web-root" || k.page || "#" || html_anchor AS href, title_plain
 FROM index_entries k INNER JOIN articles a
 ON a.page = k.page
 ORDER BY entry COLLATE NOCASE ASC, subentry COLLATE NOCASE ASC;})node|| "#" || anchor AS href, title_plain
 FROMkeywordindex k INNER JOIN articles a
 ON a.pagenode= k.pagenode  (query-rows (query-rows cache-conn q))
;; Convert a list of vectors from the cache DB into a list of the form:
;; ((FIRST-LETTER (entries ...)) ...)
;; The method relies on the records being pre-sorted by the SQL query.
(define (group-entries records)
  (define collated
    (for/fold ([entries (list (new-entry (first records)))](sqltools:dbc)q)) | 
| 
156
157
158
159
160
161
162
163
164
165
166
167
168 | 
156
157
158
159
160
161
162
163
164
165
166
167
 | 
-
 | 
 <div id="keywordindex">
 ◊the-index
 </div>
 ◊html$-page-body-close[]
 </html>})
(define (main)
(displayln "Writing keyword-index.html…")
  (display-to-file (html$-keywordindex-page (html$-index (group-entries (fetch-entries))))
                   "keyword-index.html"
                   #:mode 'text
                   #:exists 'replace))  (spell-of-summoning!) ; Turn on DB |