-
Notifications
You must be signed in to change notification settings - Fork 9
/
util-topics.rkt
50 lines (42 loc) · 1.66 KB
/
util-topics.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#lang racket/base
(require racket/string
racket/list
txexpr
pollen/core
pollen/cache
pollen/file)
(provide (all-defined-out))
#|
Index functionality: allows creation of a book-style keyword index.
* An index ENTRY refers to the heading that will appear in the index.
* An index LINK is a txexpr that has class="index-entry" and
title="ENTRY-WORD".
|#
; Given a file, returns a list of links to that file, one for each topic
; listed in the metas
(define (get-index-links pnode)
(define p-metas (cached-metas (get-source pnode)))
(define pnode-tags (select-from-metas 'topics p-metas))
(define (make-index-link itag)
`(a [[href ,(symbol->string pnode)]
[title ,itag]]
,(select-from-metas 'title p-metas)))
(if pnode-tags
(map make-index-link (string-split pnode-tags ","))
'()))
; Returns a list of index links (not entries!) for all files in file-list.
(define (collect-index-links file-list)
(apply append (map get-index-links file-list)))
; Given a list of index links, returns a list of headings (keywords). This list
; has duplicates removed and is sorted in ascending alphabetical order.
; Note that the list is case-sensitive by design; "thing" and "Thing" are
; treated as separate keywords.
(define (index-headings entrylink-list)
(sort (remove-duplicates (map (λ(tx) (attr-ref tx 'title))
entrylink-list))
string-ci<?))
; Given a heading and a list of index links, returns only the links that match
; the heading.
(define (match-index-links keyword entrylink-list)
(filter (λ(link)(string=? (attr-ref link 'title) keyword))
entrylink-list))