-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_static.v
More file actions
76 lines (68 loc) · 1.75 KB
/
generate_static.v
File metadata and controls
76 lines (68 loc) · 1.75 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
module main
import os
import time
fn write_html_file(path string, content string) ! {
os.write_file(path, content)!
println('Generated: ${path}')
}
fn render_page(title string, body string) string {
exact_time_iso := time.utc().unix_milli()
return '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${title}</title>
<link rel="stylesheet" href="css/main.css">
<script src="js/animated_value.js"></script>
<script src="js/update_timestamp.js" defer></script>
</head>
<body>
<h1>V Progress Dashboard</h1>
<hr>
${body}
<hr>
<footer>
<small class="timestamp-wrapper">
Data last updated
<span class="timestamp-fade" data-timestamp="${exact_time_iso}">
<span class="timestamp-rel">Loading...</span>
<span class="timestamp-fixed">Loading...</span>
</span>
</small>
</footer>
</body>
</html>
'
}
fn generate_static() {
os.mkdir_all('out') or {}
os.mkdir_all('out/css') or {}
os.mkdir_all('out/js') or {}
// Copy static assets
os.cp_all('static/css', 'out/css', true) or {}
os.cp_all('static/js', 'out/js', true) or {}
// Generate cards
cards := get_cards()
// Generate index.html
mut cards_html := ''
for card in cards {
cards_html += card.to_html()
}
index_content := render_page('V Progress Dashboard', '<div class="card-container">${cards_html}</div>')
write_html_file('out/index.html', index_content) or {}
// Generate one page per card
for card in cards {
full_link := card.get_full_page_link().trim_left('/')
if full_link == '' {
continue
}
full_html := render_page(card.get_title(), '
<br>
<a href="index.html" class="button">Go back to home</a>
<br><br><hr>
${card.get_full_page_content()}
')
write_html_file('out/${full_link}.html', full_html) or {}
}
}