-- splits a string to a table containing entries split by the delimiter string -- remove_chars gives all characters that have to be removed. Default is nil function split(str, delimiter, remove_chars) local t = {} local c = 1 local temp = 0 if remove_chars~=nil then str2 = string.gsub(str, remove_chars, "") else str2 = str end while c~=nil do temp = string.find(str2, delimiter, c) if temp~=nil then ins = string.sub(str2, c, temp-1) c = temp+1 else ins = string.sub(str2, c, #str) c = nil end table.insert(t, ins) end return t end -- generates html file in the out folder for function gen_pages(namelist, pnum) final = {} final["xy2video"] = {} final["meen"] = "" for i=1,#namelist-1 do xy = tostring(((i-1)%4)+1)..tostring(math.ceil(i/4)) final["xy2video"][xy] = namelist[i] if(i%4 == 1) then final["meen"] = final["meen"] .. [[
]] end final["meen"] = final["meen"] .. "\n\t"..[[
]] final["meen"] = final["meen"] .. "\n\t\t" final["meen"] = final["meen"] .. "\n\t"..[[
]] if(i%4 == 0) then final["meen"] = final["meen"] .."\n".. [[
]] end end final["meen"] = final["meen"] .."\n".. [[]] final["xy2video"] = utils.table_to_json(final["xy2video"]) templ = io.open("template.html", "r") template = templ:read("*all") f = io.open("out/bombadil_"..pnum..".html", "a") f:write(string.gsub(template, "{(.-)}", final)) return 0 end f = io.open("names.txt", 'r') file = f:read("*all") temp = split(file, "\n") n_pages = math.ceil(#temp/40) for j=1,n_pages do subl = {} for k=((j-1)*40+1),math.min(#temp,(j*40)) do subl[k-((j-1)*40)] = temp[k] end gen_pages(subl, j) end