Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgenerate.lua
More file actions
Latest commit
189 lines (184 loc) · 6.01 KB
/
Copy pathgenerate.lua
File metadata and controls
189 lines (184 loc) · 6.01 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
--[[
a HTML/CSS generator, designed to make updating the site easier
--]]
os.execute("cd "..(...or""))
localerr,https=pcall(require,"https")
localarg=...
ifnoterrthen
print("you need to install luasec")
print("install using luarocks")
print("or https://github.com/brunoos/luasec/wiki")
print(https)
os.exit()
end
localres,err=xpcall(function()
localfile=assert(io.open((argor"").."repos.cfg","r"))
localrepodat=load("return "..file:read("*a"), nil, nil, {})()
file:close()
localrepos={}
forname,datainpairs(repodat) do
localout={
name,(data.repoor"none")
}
fork,vinpairs(data.programsor {}) do
table.insert(out,{
k,v.repo,v.desc
})
end
table.insert(repos,out)
end
table.sort(repos,function(a,b)
returna[1]:lower()<b[1]:lower()
end)
-- crappy parsing
localfunctionparse(yaml)
localout={}
forlineinyaml:gmatch("[^\r\n]+") do
ifnotline:match("^#") then
localt,m=line:match("^(%s*)(.*)")
t=t:gsub("","\t")
if#t==0and#m>0then
table.insert(out,{m:match("(.+):")})
elseif#t==1then
ifm:match(":$") then
table.insert(out[#out],{m:match("(.+):")})
else
table.insert(out[#out],m)
end
elseif#t==2then
localt=out[#out]
table.insert(t[#t],m)
end
end
end
returnout
end
localfunctionget(url)
localres,code=https.request(url)
ifcode==200then
returnres
end
end
forl1=1,#reposdo
localprog=repos[l1]
ifprog[2]~="none" then
localdata=get("https://raw.githubusercontent.com/"..prog[2].."/master/programs.cfg")
ifdatathen
data,err=load("return "..data, nil, nil, {})
ifnotdatathen
print("Error in "..prog[2])
error(err)
end
data=data()
forname,datinpairs(data) do
ifnotdat.hiddenthen
ifdat.repothen
ifstring.match(dat.repo, "^https?://.+") then
table.insert(prog,{
name,
dat.repo,
dat.description,
})
else
table.insert(prog,{
name,
prog[2].."/"..dat.repo,
dat.description,
})
end
else
table.insert(prog,{
name,
nil,
dat.description,
})
end
end
end
localn, r=prog[1], prog[2]
table.sort(prog, function(a,b)
ifa==nthenreturntrue
elseifb==nthenreturnfalse
elseifa==rthenreturntrue
elseifb==rthenreturnfalse
elsereturna[1]:lower()<b[1]:lower()
end
end)
else
print("WARNING: "..prog[2].." doesnt have a programs.cfg")
localdata=get("https://raw.githubusercontent.com/"..prog[2].."/master/programs.yaml")
ifdatathen
repos[l1]=parse(data)
table.insert(repos[l1],1,prog[2])
table.insert(repos[l1],1,prog[1])
else
print("WARNING: "..prog[2].." doesnt have a programs.yaml and cant be listed")
end
end
end
end
localurl_override_because_vexatos={
["immibis-compress"]="/tree/master/immibis-compress",
ipack="/blob/master/immibis-compress/ipack.lua",
dnsd="/blob/master/dns-server.lua",
}
localhtml=[[
<html>
<head>
<title>OpenPrograms</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/ico" href="favicon.ico">
<script src="scripts/search.js"></script>
</head>
<body>
<center><a href="https://github.com/OpenPrograms"><img src="logo.png"></a></center>
<div class="bvc" align="right"><input type="text" id="searchbox" placeholder="Search for something here" size="30" maxlength="60" oninput="search();"/><input type="button" id="btnSearch" value="Search" onclick="search();" /></div>
]]
print("\ngenerating page\n")
for_,datinpairs(repos) do
localname=dat[1]
print("repo "..tostring(name))
ifdat[2]~="none" then
dat[2]="https://github.com/"..dat[2]
html=html.."\t\t<div align=\"left\" name=\"content\" class=\"bvc\"><div class=\"bevel tl tr\"></div><div class=\"content\"><a href=\""..dat[2].."\"><div class=\"title\">"..name.."</div></a>"
else
dat[2]="https://github.com/"
html=html.."\t\t<div align=\"left\" name=\"content\" class=\"bvc\"><div class=\"bevel tl tr\"></div><div class=\"content\"><div class=\"title\">"..name.."</div>"
end
html=html.."\n\t\t<table>\n"
forind=3,#datdo
localpdat=dat[ind]
iftype(pdat)=="table" then
print("\tprogram "..tostring(pdat[1]))
localurl=pdat[2] orurl_override_because_vexatos[pdat[1]]
ifurlthen
ifurl:sub(1,1)=="/" then
url=dat[2]..url
elseifnoturl:match("^https?://.+") then
url="https://github.com/"..url
end
html=html.."\t\t\t<tr><td><a href=\""..url.."\">"..pdat[1].."</a></td><td>: "..pdat[3].."</td></tr>\n"
else
print("\t\tWARNING: "..pdat[1].." doesnt have a url!")
html=html.."\t\t\t<tr><td><a style=\"color:#505050\">"..pdat[1].."</a></td><td>: "..pdat[3].."</td></tr>\n"
end
else
html=html.."\t\t\t"..pdat.."\n"
end
end
html=html.."\t\t</table></div><div class=\"bevel bl br\"></div></div>\n"
end
localdate=os.date("!*t")
localgen=date.month.."/"..date.day.." at "..date.hour..":"..("0"):rep(2-#tostring(date.min))..date.min
html=html..[[
</body>
</html>
]]
localfile=assert(io.open((argor"").."index.html","w"))
file:write(html)
file:close()
end,debug.traceback)
ifnotresthen
print(err)
end