Added keywords from doc.txt files to the master index page.

svn: r7345
This commit is contained in:
Jens Axel Soegaard 2007-09-15 15:12:33 +00:00
parent 827b68274b
commit 78b57246a2
2 changed files with 70 additions and 18 deletions

View File

@ -10,7 +10,10 @@
(lib "contract.ss")
(lib "dirs.ss" "setup"))
(provide doc-collections-changed)
(provide doc-collections-changed
reset-doc-lists
extract-doc-txt
load-txt-keywords-into-hash-table)
(provide/contract
[do-search
(string?
@ -189,10 +192,14 @@
(define re:keyword-line (regexp "\n>"))
(define text-keywords (make-hash-table 'equal))
(define (load-txt-keywords doc)
(load-txt-keywords-into-hash-table text-keywords doc))
(define (load-txt-keywords-into-hash-table ht doc)
(parse-txt-file
(apply build-path doc)
text-keywords
ht
(λ (p)
(port-count-lines! p)
(let loop ()

View File

@ -5,10 +5,12 @@
(lib "dirs.ss" "setup")
(lib "list.ss")
(lib "match.ss")
(lib "uri-codec.ss" "net")
"../private/options.ss"
"private/url.ss"
"../private/standard-urls.ss"
"private/html.ss")
"private/html.ss"
"../private/search.ss")
(provide interface-version timeout start)
(define interface-version 'v1)
@ -30,7 +32,10 @@
;;; ENTRIES
;;;
(define-struct entry (keyword host manual file label title) (make-inspector))
(define-struct entry (keyword) (make-inspector))
(define-struct (manual-entry entry) (host manual file label title) (make-inspector))
(define-struct (doc.txt-entry entry) (file offset title))
(define entries (make-hash-table 'equal))
;;;
@ -41,10 +46,15 @@
; convert entry into link
(define (html-entry the-entry)
(match the-entry
[($ entry keyword host manual file label title)
[($ manual-entry keyword host manual file label title)
`(div 'nbsp 'nbsp 'nbsp 'nbsp
(a ([href ,(file-path->url host manual file label)])
,title))]))
(a ([href ,(manual-file-path->url host manual file label)])
,title))]
[($ doc.txt-entry keyword file offset title)
`(div 'nbsp 'nbsp 'nbsp 'nbsp
(a ([href ,(doc.txt-file-path->url file title keyword offset)])
,title))]
[_ (error)]))
; html-keyword : string -> xexpr
; make xexpr with the keyword in bold followed by all associated entries
@ -54,18 +64,28 @@
; html-master-index : -> xexpr
(define (html-master-index)
(let ([keywords (sort (hash-table-map entries (lambda (key val) key)) string<?)])
(let ([keywords (sort (hash-table-map entries (lambda (key val) key))
(lambda (s1 s2) (string<? (string-downcase s1) (string-downcase s2))))])
`(div (h1 "Master Index")
(p "This master index contains all keywords from the tex2page based manuals.")
(p "This master index contains all keywords from the tex2page based manuals as well as doc.txt files.")
(p "All entries in keywords and hdindex files are thus included.")
(p "Keywords from Scribble generated manuals are not included yet.")
(p "PLaneT documentation is not included.")
,@(map html-keyword keywords))))
; file-path->url : string string path string -> string
(define (file-path->url host manual file label)
; manual-file-path->url : string string path string -> string
(define (manual-file-path->url host manual file label)
(string-append (url-static host manual file)
(if label (format "#~a" label) "")))
(define (doc.txt-file-path->url file caption name offset)
(format "/servlets/doc-anchor.ss?file=~a&caption=~a&name=~a&offset=~a#temp"
(path->string file)
(uri-encode caption)
(uri-encode name)
offset))
;;;
;;; ENTRIES
;;;
@ -77,23 +97,23 @@
[old (hash-table-get entries keyword (lambda () '()))])
(hash-table-put! entries (entry-keyword entry) (cons entry old))))
; keyword->entry : string string list-from-keywords-file -> entry
; convert list from keywords-file into an entry
; keyword->entry : string string list-from-keywords-file -> manual-entry
; convert list from keywords-file into an manual-entry
(define (keyword->entry host manual keyword-list)
(match keyword-list
[(keyword result-display html-file html-label title)
(make-entry keyword host manual html-file html-label title)]
(make-manual-entry keyword host manual html-file html-label title)]
[_
(error 'keyword->entry
"Expected a five element list: (<keyword> <result-to-display> <html-file> <html-label> <title>), got: "
keyword-list)]))
; item->entry : string string list-from-hdindex-files -> entry
; item->entry : string string list-from-hdindex-files -> manual-entry
; convert list from hdindex file into an entry
(define (item->entry host manual item-list)
(match item-list
[(item html-file html-label title)
(make-entry item host manual html-file html-label title)]
(make-manual-entry item host manual html-file html-label title)]
[_
(error 'item->entry
"Expected a four element list: (<item> <html-file> <html-label> <title>), got: "
@ -116,7 +136,7 @@
keyword-entries))))))))
; add-items-in-directory! : string string path ->
; add all items in <dir>/keywords to the entries hash-table
; add all items in <dir>/hdindex to the entries hash-table
(define (add-items-in-directory! host manual dir)
(when (directory-exists? dir)
(let ([items-path (build-path dir "hdindex")])
@ -138,9 +158,34 @@
(add-keywords-in-directory! host manual (build-path dir manual))
(add-items-in-directory! host manual (build-path dir manual)))
(directory-list dir)))]))
(define (add-keywords-in-doc.txt-file doc name)
(let ([ht (make-hash-table 'equal)])
(load-txt-keywords-into-hash-table ht doc)
(hash-table-for-each
ht (lambda (key val)
(for-each (lambda (item)
(match item
[(keyword title doc.txt-path offset _)
(add-entry!
(make-doc.txt-entry keyword key offset title))]))
val)))))
; add-keywords-in-doc.txt-files : ->
(define (add-keywords-in-doc.txt-files)
(reset-doc-lists)
(let-values ([(pathss names types) (extract-doc-txt)])
(for-each
(lambda (paths name type)
(match paths
[(base-path doc-txt)
(add-keywords-in-doc.txt-file paths name)]))
pathss names types)))
; make the traversal
(for-each add-keywords-in-sub-directories!
host+dirs)
)
(add-keywords-in-doc.txt-files)
)