forked from GeertArien/learnopengl-examples
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpage.lua
136 lines (126 loc) · 4.38 KB
/
webpage.lua
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
import("core.base.json")
local GitHubExamplesURL = "https://github.com/zeromake/learnopengl-examples/tree/master/src"
local WebpageDeployDir = "docs"
local items = json.loadfile("index.json")
local assets = {
"awesomeface.png",
"backpack.mtl",
"backpack.obj",
"backpack_diffuse.jpg",
"backpack_normal.png",
"backpack_specular.jpg",
"brickwall.jpg",
"brickwall_normal.jpg",
"container.jpg",
"container2.png",
"container2_specular.png",
"grass.png",
"marble.jpg",
"mars.png",
"metal.png",
"planet.mtl",
"planet.obj",
"rock.mtl",
"rock.obj",
"rock.png",
"skybox_right.jpg",
"skybox_left.jpg",
"skybox_top.jpg",
"skybox_bottom.jpg",
"skybox_front.jpg",
"skybox_back.jpg",
"transparent_window.png",
"uv_grid.png",
"wood.png"
}
local webpageAssets = {
'img/dummy.jpg',
'img/favicon.png',
'fontello.woff',
'fontello.woff2'
}
if not os.exists(WebpageDeployDir) then
os.mkdir(WebpageDeployDir)
end
local function split(input, delimiter)
if (delimiter == "") then return false end
local pos, arr = 0, {}
for st, sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
local indexContent = io.readfile("webpage/index.html")
local wasmContent = io.readfile("webpage/wasm.html")
local function example_wasm(dir, example, content)
local filename = example[2]
local source = example[3]
local glsl = example[4]
local glsl_hidden = "hidden"
local glsl_url = "."
local src_url = GitHubExamplesURL.."/"..dir.."/"..source
local src_path = GitHubExamplesURL.."/"..dir.."/"..source..".js"
if glsl ~= "" then
glsl_hidden = ""
glsl_url = GitHubExamplesURL.."/"..dir.."/"..glsl
end
local arr = split(filename, '-')
local progname = arr[1].."-"..arr[2].."-"..arr[3]
content = content:gsub('$%{name%}', filename)
content = content:gsub('$%{prog%}', progname)
content = content:gsub('$%{source%}', src_url)
content = content:gsub('$%{glsl%}', glsl_url)
content = content:gsub('$%{hidden%}', glsl_hidden)
io.writefile("docs/"..filename..".html", content)
end
local content = ''
for _, chapter in ipairs(items) do
local chapter_title = chapter[1]
local lessons = chapter[2]
content = content..format('<h2>%s</i></h2>\n', chapter_title)
for _, lesson in ipairs(lessons) do
local lesson_title = lesson[1]
local lesson_link = lesson[2]
local dir = lesson[3]
local examples = lesson[4]
content = content..'<article>\n'
content = content..format(
'<section class="header"><h3><a href="%s">%s <i class="icon-link-ext"></i></a></h3></section>\n',
lesson_link,
lesson_title)
content = content..'<section class="group examples">\n'
for _, example in ipairs(examples) do
local name = example[1]
local filename = example[2]
local url = format("%s.html", filename)
local img_name = filename .. '.jpg'
local img_path = 'webpage/img/' .. img_name
if not os.exists(img_path) then
img_name = 'dummy.jpg'
img_path = 'webpage/img/dummy.jpg'
end
os.cp(img_path, "docs/")
content = content..'<figure class="col-15">\n'
content = content..format('<figcaption><h4>%s</h4></figcaption>\n', name)
content = content..format('<div><img class="responsive" src="%s" alt=""></div>\n', img_name)
content = content..format('<a href="%s">Read More</a>\n', url)
content = content..'</figure>\n'
example_wasm(dir, example, wasmContent)
end
content = content..'</section>\n'
content = content..'</article>\n'
end
content = content..'<hr>\n'
end
indexContent = indexContent:gsub('$%{samples%}', content):gsub('$%{date%}', os.date('!%Y-%m-%d %H:%M:%S +00:00', os.time()))
io.writefile("docs/index.html", indexContent)
for _, asset in ipairs(assets) do
os.cp(path.join("src/data", asset), "docs/")
end
for _, asset in ipairs(webpageAssets) do
os.cp(path.join("webpage", asset), "docs/")
end
os.cp("build/wasm/wasm64/release/*.js", "docs/")
os.cp("build/wasm/wasm64/release/*.wasm", "docs/")