Overview
| Comment: | Implement adding index entries via ‘keywords’ meta | 
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk | 
| Files: | files | file ages | folders | 
| SHA3-256: | ecb3576a79b168d95a72f0d6df3420f6 | 
| User & Date: | joel on 2020-03-15 21:42:54 | 
| Other Links: | manifest | tags | 
Context
| 2020-03-20 | ||
| 03:24 | Add and document save-cache-things! check-in: cbaca7d9 user: joel tags: trunk | |
| 2020-03-15 | ||
| 21:42 | Implement adding index entries via ‘keywords’ meta check-in: ecb3576a user: joel tags: trunk | |
| 21:42 | Update keywords in ‘Goodnight, Irene: Scene 1’ check-in: 708efa1d user: joel tags: trunk, errata | |
Changes
Modified cache.rkt from [22c08e42] to [766a00d5].
| ︙ | ︙ | |||
| 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 
         cache-conn                     ; The most eligible bachelor in Neo Yokyo
         (schema-out cache:article)
         (schema-out cache:note)
         (schema-out cache:index-entry)
         (schema-out listing)
         delete-article!
         delete-notes!
         articles
         articles+notes
         listing-htmls
         fenced-listing
         unfence)
;; Cache DB and Schemas
 | > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 
         cache-conn                     ; The most eligible bachelor in Neo Yokyo
         (schema-out cache:article)
         (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)
;; Cache DB and Schemas
 | 
| ︙ | ︙ | |||
| 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 
(define (delete-notes! page)
  (query-exec (cache-conn)
              (~> (from cache:note #:as n)
                  (where (= n.page ,(format "~a" page)))
                  delete)))
;;
;;  ~~~ Fetching articles and notes ~~~
;;
;; (Private use) Conveniece function for the WHERE `series-page` clause
(define (where-series q s)
  (define (s->p x) (format "~a/~a.html" series-folder x))
 | > > > > > > > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | 
(define (delete-notes! page)
  (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
(define (where-series q s)
  (define (s->p x) (format "~a/~a.html" series-folder x))
 | 
| ︙ | ︙ | 
Modified crystalize.rkt from [7aa92528] to [b135d898].
| ︙ | ︙ | |||
| 237 238 239 240 241 242 243 244 245 246 247 248 | 
  (match (split-entry (attr-ref tx 'data-index-entry))
    [(list main sub)
     (make-cache:index-entry
      #:entry main
      #:subentry sub
      #:page pagenode
      #:html-anchor (attr-ref tx 'id))]))
;; 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?))
 | > > > > > > > > > > > | | | | | | | < | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | 
  (match (split-entry (attr-ref tx 'data-index-entry))
    [(list main sub)
     (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?))
  (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))
  
 |