Index: cache.rkt ================================================================== --- cache.rkt +++ cache.rkt @@ -18,10 +18,12 @@ (schema-out cache:note) (schema-out cache:index-entry) (schema-out listing) delete-article! delete-notes! + delete-index-entries! + save-index-entries! articles articles+notes listing-htmls fenced-listing unfence) @@ -99,10 +101,19 @@ (query-exec (cache-conn) (~> (from cache:note #:as n) (where (= n.page ,(format "~a" page))) delete))) +(define (delete-index-entries! page) + (query-exec (cache-conn) + (~> (from cache:index-entry #:as e) + (where (= e.page ,(format "~a" page))) + delete))) + +(define (save-index-entries! es) + (void (apply insert! (cache-conn) es))) + ;; ;; ~~~ Fetching articles and notes ~~~ ;; ;; (Private use) Conveniece function for the WHERE `series-page` clause Index: crystalize.rkt ================================================================== --- crystalize.rkt +++ crystalize.rkt @@ -239,18 +239,28 @@ (make-cache:index-entry #:entry main #:subentry sub #:page pagenode #:html-anchor (attr-ref tx 'id))])) + +;; Get index entries out of metas +(define (current-metas-keyword-entries pagenode) + (for/list ([kw (in-list (string-split (maybe-meta 'keywords "") #px",\\s*"))]) + (match (split-entry kw) + [(list main sub) + (make-cache:index-entry + #:entry main + #:subentry sub + #:page pagenode + #:html-anchor "")]))) ;; Save any index entries in doc to the SQLite cache. ;; Sub-entries are specified by "!" in the index key (define (cache-index-entries! pagenode doc) (define-values (_ entry-txs) (splitf-txexpr doc index-entry-txpr?)) - ; Naive idempotence: delete and re-insert all index entries every time doc is rendered. - (query-exec (cache-conn) (delete (~> (from cache:index-entry #:as entry) - (where (= entry.page ,(symbol->string pagenode)))))) - (unless (null? entry-txs) - (void - (apply insert! (cache-conn) - (for/list ([etx (in-list entry-txs)]) - (txexpr->index-entry etx pagenode)))))) + (define all-entries + (append (for/list ([etx (in-list entry-txs)]) (txexpr->index-entry etx pagenode)) + (current-metas-keyword-entries pagenode))) + + (delete-index-entries! pagenode) + (save-index-entries! all-entries)) +