Skip to content

Commit 1752a4e

Browse files
committed
add the query-table argument to perform-search and send-main-page and add contracts
1 parent ce7d5b1 commit 1752a4e

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

scribble-lib/help/search.rkt

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44
net/uri-codec
55
net/url
66
racket/string
7-
setup/dirs)
8-
(provide perform-search send-main-page)
7+
setup/dirs
8+
racket/contract
9+
racket/list)
10+
11+
(provide
12+
(contract-out
13+
[perform-search
14+
(->* (any/c)
15+
(any/c #:query-table (hash/c symbol? string? #:immutable #t))
16+
void?)]
17+
[send-main-page
18+
(->* ()
19+
(#:sub string?
20+
#:fragment (or/c string? #f)
21+
#:query (or/c string? #f)
22+
#:notify (-> (or/c string? path?) any)
23+
#:query-table (hash/c symbol? string? #:immutable #t))
24+
void?)]))
925

1026
(define search-dir "search/")
1127

@@ -14,7 +30,11 @@
1430

1531
(define (send-main-page #:sub [sub "index.html"]
1632
#:fragment [fragment #f] #:query [query #f]
17-
#:notify [notify void])
33+
#:notify [notify void]
34+
#:query-table [query-table (hash)])
35+
(define query-table-list-of-pairs
36+
(for/list ([k (in-list (sort (hash-keys query-table) symbol<?))])
37+
(cons k (hash-ref query-table k))))
1838
(define open-url (get-doc-open-url))
1939
(cond
2040
[open-url
@@ -35,7 +55,8 @@
3555
(url-query
3656
(string->url
3757
(format "q?~a" query)))
38-
null))])))]
58+
null)
59+
query-table-list-of-pairs)])))]
3960
[else
4061
(define path (or (for/or ([dir (in-list (get-doc-search-dirs))])
4162
(define path (build-path dir sub))
@@ -44,13 +65,26 @@
4465
;; Doesn't exist, but notify and then fall back below:
4566
(build-path (find-doc-dir) sub)))
4667
(notify path)
68+
(define parsed-query-table
69+
(if (null? query-table-list-of-pairs)
70+
#f
71+
(substring (url->string (url #f #f #f #f #f (list) query-table-list-of-pairs #f))
72+
1)))
73+
(define combined-query
74+
(cond
75+
[(and query parsed-query-table)
76+
(string-append query "&" parsed-query-table)]
77+
[else
78+
(or query parsed-query-table)]))
4779
(cond
48-
[(file-exists? path) (send-url/file path #:fragment fragment #:query query)]
80+
[(file-exists? path) (send-url/file path #:fragment fragment #:query combined-query)]
4981
[else
5082
(define (part pfx x)
5183
(if x (string-append pfx x) ""))
5284
(send-url
53-
(string-append "https://docs.racket-lang.org/" sub (part "#" fragment) (part "?" query)))])]))
85+
(string-append "https://docs.racket-lang.org/" sub
86+
(part "#" fragment)
87+
(part "?" combined-query)))])]))
5488

5589
;; This is an example of changing this code to use the online manuals.
5690
;; Normally, it's better to set `doc-open-url` in "etc/config.rktd",
@@ -67,7 +101,8 @@
67101
;; "http://download.racket-lang.org/docs/" (version) "/html/"
68102
;; sub (part "#" fragment) (part "?" query))))
69103

70-
(define (perform-search str [context #f])
104+
(define (perform-search str [context #f]
105+
#:query-table [query-table (hash)])
71106
;; `context' can be a pre-filter query string to use for a context,
72107
;; optionally a list of one and a label to display for that context.
73108
;; In any case, when a context is specified, the search actually
@@ -85,4 +120,5 @@
85120
(format "&label=~a" (uri-encode label))
86121
""))
87122
query)])
88-
(send-main-page #:sub (string-append search-dir page) #:query query)))
123+
(send-main-page #:sub (string-append search-dir page) #:query query
124+
#:query-table query-table)))

scribble-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
(define pkg-authors '(mflatt eli))
2323

24-
(define version "1.59")
24+
(define version "1.60")
2525

2626
(define license
2727
'((Apache-2.0 OR MIT)

0 commit comments

Comments
 (0)