1 ! Copyright (C) 2008, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: checksums checksums.sha io.encodings.utf8
4 io.encodings.binary io.encodings.string io.files io.files.temp
5 io.directories html.streams help help.home kernel assocs
6 sequences make words accessors arrays help.topics vocabs
7 vocabs.hierarchy help.vocabs namespaces io vocabs.loader
8 serialize fry memoize unicode.case math.order sorting debugger
9 html xml.syntax xml.writer math.parser sets hashtables ;
10 FROM: io.encodings.ascii => ascii ;
11 FROM: ascii => ascii? ;
14 GENERIC: topic>filename* ( topic -- name prefix )
16 M: word topic>filename*
18 [ name>> ] [ vocabulary>> ] bi 2array "word"
21 M: link topic>filename* name>> dup [ "article" ] [ topic>filename* ] if ;
22 M: word-link topic>filename* name>> topic>filename* ;
23 M: vocab-spec topic>filename* vocab-name "vocab" ;
24 M: vocab-tag topic>filename* name>> "tag" ;
25 M: vocab-author topic>filename* name>> "author" ;
26 M: f topic>filename* drop \ f topic>filename* ;
28 : topic>filename ( topic -- filename )
32 dup array? [ "," join ] when
33 utf8 encode sha1 checksum-bytes hex-string
38 M: topic url-of topic>filename ;
40 : help-stylesheet ( -- xml )
41 "vocab:help/html/stylesheet.css" ascii file-contents
42 [XML <style><-></style> XML] ;
44 : help-navbar ( -- xml )
45 "conventions" >link topic>filename
48 <b> Factor Documentation </b> |
49 <a href="/">Home</a> |
50 <a href=<->>Glossary</a> |
51 <form method="get" action="/search" style="display:inline;">
52 <input name="search" type="text"/>
53 <button type="submit">Search</button>
55 <a href="http://factorcode.org" style="float:right; padding: 4px;">factorcode.org</a>
59 : help>html ( topic -- xml )
60 [ article-title " - Factor Documentation" append ]
61 [ drop help-stylesheet ]
64 [ [ print-topic ] with-html-writer ]
69 : generate-help-file ( topic -- )
70 dup topic>filename utf8 [ help>html write-xml ] with-file-writer ;
72 : all-vocabs-really ( -- seq )
73 all-vocabs-recursive >hashtable no-roots remove-redundant-prefixes
74 [ vocab-name "scratchpad" = not ] filter ;
76 : all-topics ( -- topics )
78 articles get keys [ >link ] map %
79 all-words [ >link ] map %
80 all-authors [ <vocab-author> ] map %
81 all-tags [ <vocab-tag> ] map %
85 : serialize-index ( index file -- )
86 [ [ [ topic>filename ] dip ] { } assoc-map-as object>bytes ] dip
87 binary set-file-contents ;
89 : generate-indices ( -- )
90 articles get keys [ [ >link ] [ article-title ] bi ] { } map>assoc "articles.idx" serialize-index
91 all-words [ dup name>> ] { } map>assoc "words.idx" serialize-index
92 all-vocabs-really [ dup vocab-name ] { } map>assoc "vocabs.idx" serialize-index ;
94 : (generate-help-files) ( -- )
95 all-topics [ '[ _ generate-help-file ] try ] each ;
97 : generate-help-files ( -- )
103 (generate-help-files)
106 : generate-help ( -- )
116 MEMO: load-index ( name -- index )
117 binary file-contents bytes>object ;
119 TUPLE: result title href ;
121 : partition-exact ( string results -- results' )
122 [ title>> = ] with partition append ;
124 : offline-apropos ( string index -- results )
125 load-index over >lower
126 '[ [ drop _ ] dip >lower subseq? ] assoc-filter
127 [ swap result boa ] { } assoc>map
128 [ title>> ] sort-with
131 : article-apropos ( string -- results )
132 "articles.idx" offline-apropos ;
134 : word-apropos ( string -- results )
135 "words.idx" offline-apropos ;
137 : vocab-apropos ( string -- results )
138 "vocabs.idx" offline-apropos ;