|
6 | 6 | racket/string |
7 | 7 | setup/dirs |
8 | 8 | racket/contract |
9 | | - racket/list) |
| 9 | + racket/list |
| 10 | + scribble/xref |
| 11 | + setup/language-family) |
10 | 12 |
|
11 | 13 | (provide |
12 | 14 | (contract-out |
13 | 15 | [perform-search |
14 | 16 | (->* (any/c) |
15 | | - (any/c #:query-table (hash/c symbol? string? #:immutable #t)) |
| 17 | + (any/c #:language-family (or string? #f)) |
16 | 18 | void?)] |
17 | 19 | [send-main-page |
18 | 20 | (->* () |
19 | | - (#:sub string? |
| 21 | + (#:sub path-string? |
20 | 22 | #:fragment (or/c string? #f) |
21 | 23 | #:query (or/c string? #f) |
22 | 24 | #:notify (-> (or/c string? path?) any) |
23 | 25 | #:query-table (hash/c symbol? string? #:immutable #t)) |
| 26 | + void?)] |
| 27 | + [send-language-family-page |
| 28 | + (->* ((or/c #f string?)) |
| 29 | + () |
24 | 30 | void?)])) |
25 | 31 |
|
26 | 32 | (define search-dir "search/") |
|
59 | 65 | query-table-list-of-pairs)])))] |
60 | 66 | [else |
61 | 67 | (define doc-dirs (get-doc-search-dirs)) |
62 | | - (define path (or (for/or ([dir (in-list doc-dirs)]) |
| 68 | + (define path (or (and (absolute-path? sub) |
| 69 | + sub) |
| 70 | + (for/or ([dir (in-list doc-dirs)]) |
63 | 71 | (define path (build-path dir sub)) |
64 | 72 | (and (file-exists? path) |
65 | 73 | path)) |
|
89 | 97 | root)] |
90 | 98 | [else combined-base-query])) |
91 | 99 | (cond |
92 | | - [(file-exists? path) (send-url/file path #:fragment fragment #:query combined-query)] |
| 100 | + [(or (file-exists? path) (path? sub)) |
| 101 | + (send-url/file path #:fragment fragment #:query combined-query)] |
93 | 102 | [else |
94 | 103 | (define (part pfx x) |
95 | 104 | (if x (string-append pfx x) "")) |
|
114 | 123 | ;; sub (part "#" fragment) (part "?" query)))) |
115 | 124 |
|
116 | 125 | (define (perform-search str [context #f] |
117 | | - #:query-table [query-table (hash)]) |
| 126 | + #:language-family [language-family #f]) |
118 | 127 | ;; `context' can be a pre-filter query string to use for a context, |
119 | 128 | ;; optionally a list of one and a label to display for that context. |
120 | 129 | ;; In any case, when a context is specified, the search actually |
|
131 | 140 | (if label |
132 | 141 | (format "&label=~a" (uri-encode label)) |
133 | 142 | "")) |
134 | | - query)]) |
135 | | - (send-main-page #:sub (string-append search-dir page) #:query query |
136 | | - #:query-table query-table))) |
| 143 | + query)] |
| 144 | + [fam (and language-family (get-language-family language-family))] |
| 145 | + [famroot (and fam (hash-ref fam 'famroot #f))]) |
| 146 | + (send-main-page #:sub (string-append search-dir page) |
| 147 | + #:query query |
| 148 | + #:query-table (if fam |
| 149 | + (family-query-table fam language-family) |
| 150 | + (hash))))) |
| 151 | + |
| 152 | +(define (send-language-family-page name) |
| 153 | + (define fam (get-language-family name)) |
| 154 | + (define start-doc (and fam |
| 155 | + (or (hash-ref fam 'start-doc #f) |
| 156 | + (hash-ref fam 'doc #f)))) |
| 157 | + (define famroot (and fam (hash-ref fam 'famroot #f))) |
| 158 | + (cond |
| 159 | + [start-doc |
| 160 | + (define xref ((dynamic-require 'setup/xref 'load-collections-xref))) |
| 161 | + (define-values (path anchor) |
| 162 | + (xref-tag->path+anchor xref `(part (,(format "~a" start-doc) "top")))) |
| 163 | + (cond |
| 164 | + [path (send-main-page #:sub path #:query-table (family-query-table fam name))] |
| 165 | + [else (send-main-page)])] |
| 166 | + [famroot |
| 167 | + (send-main-page #:sub (format "~a/index.html" famroot) #:query-table (family-query-table fam name))] |
| 168 | + [else |
| 169 | + (send-main-page)])) |
| 170 | + |
| 171 | +(define (get-language-family name) |
| 172 | + (define fams (get-language-families)) |
| 173 | + (for/or ([fam (in-list fams)]) |
| 174 | + (and (equal? name (hash-ref fam 'fam #f)) |
| 175 | + fam))) |
| 176 | + |
| 177 | +(define (family-query-table fam name) |
| 178 | + (define ht (hash 'fam (hash-ref fam 'fam name))) |
| 179 | + (define famroot (hash-ref fam 'famroot #f)) |
| 180 | + (if famroot |
| 181 | + (hash-set ht 'famroot famroot) |
| 182 | + ht)) |
0 commit comments