@@ -16,10 +16,11 @@ (require pollen/setup pollen/core pollen/template racket/string racket/function + racket/list txexpr db/base "sqlite-tools.rkt" "snippets-html.rkt" "dust.rkt") @@ -332,11 +333,22 @@ (define (article-plain-title pagenode) (query-value (sqltools:dbc) "SELECT `title_plain` FROM `articles` WHERE `pagenode` = ?1" (symbol->string pagenode))) ;; ~~~ Keyword Index Entries ~~~ -;; (private) Save any index entries in doc to the cache +;; (private) Convert an entry key into a list of at most two elements, +;; a main entry and a sub-entry. +;; "entry" → '("entry" "") +;; "entry!sub" → '("entry" "sub") +;; "entry!sub!why?!? '("entry" "sub") +(define (split-entry str) + (define splits (string-split str "!")) + (list (car splits) + (cadr (append splits (list ""))))) + +;; (private) Save any index entries in doc to the SQLite cache +;; Sub-entries are specified by "!" in the index key (define (crystalize-index-entries! pagenode doc) (define (index-entry? tx) (and (txexpr? tx) (string=? "index-link" (attr-ref tx 'class "")) ; see definition of html-index (attr-ref tx 'data-index-entry #f))) @@ -346,12 +358,13 @@ (query! "DELETE FROM `keywordindex` WHERE `pagenode` = ?1" (symbol->string pagenode)) (unless (null? entries) (define entry-rows (for/list ([entry-tx (in-list entries)]) - (list (attr-ref entry-tx 'data-index-entry) - "" ; subentries not yet implemented + (define entry-parts (split-entry (attr-ref entry-tx 'data-index-entry))) + (list (first entry-parts) + (second entry-parts) (symbol->string pagenode) (attr-ref entry-tx 'id)))) (query! (make-insert-rows-query "keywordindex" table_keywordindex-fields entry-rows)))) ;; ~~~ Series ~~~