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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
--------------------------------------------------------------------------------
-- search in help
-- that file defines all the tools and goodies to allow search
--------------------------------------------------------------------------------
local entries = {}
paths.install_dok = paths.concat(paths.install_html, '..', 'dok')
paths.install_dokmedia = paths.concat(paths.install_html, '..', 'dokmedia')
local function html2entries(html, package, file)
local dnext = html:gfind('<div.->(.-)</div>')
for div in dnext do
local next = div:gfind('<h%d><a.->%s+(.-)%s+</a></h%d><a.-></a>\n<a name="(.-)"></a>\n(.-)$')
for title,link,body in next do
link = package .. '/' .. file:gsub('.txt','.html') .. '#' .. link
body = body:gsub('<img.->','')
entries.global = entries.global or {}
table.insert(entries.global, {title, link, body})
entries[package] = entries[package] or {}
table.insert(entries[package], {title, '../' .. link, body})
end
end
return entries
end
local function install(entries, dir)
local vars = {}
for i,entry in ipairs(entries) do
table.insert(vars, 's[' .. (i-1) .. '] = "'
.. table.concat(entry, '^~^'):gsub('"','\\"'):gsub('\n',' ') .. '";')
end
local array = table.concat(vars, '\n')
array = array:gsub('%%','PERCENTFUCK')
local f = paths.concat(paths.install_html, paths.basename(dir), 'jse_form.js')
if paths.filep(f) then
local js = io.open(f):read('*all')
js = js:gsub('// SEARCH_ARRAY //', array)
js = js:gsub('PERCENTFUCK','%')
local w = io.open(f,'w')
w:write(js)
w:close()
end
end
function dok.installsearch()
print('-- parsing dok files to build search index')
for package in paths.files(paths.install_dok) do
if package ~= '.' and package ~= '..' then
local dir = paths.concat(paths.install_dok, package)
for file in paths.files(dir) do
if file ~= '.' and file ~= '..' then
print('-+ parsing file: ' .. paths.concat(dir,file))
local path = paths.concat(dir, file)
local f = io.open(path)
if f then
local content = f:read('*all')
local html = dok.dok2html(content)
local entries = html2entries(html, package, file)
end
end
end
end
end
for package,entries in pairs(entries) do
print('-+ installing search for package: ' .. package)
if package == 'global' then package = '.' end
install(entries, package)
end
end
|