-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlol.rb
73 lines (58 loc) · 1.9 KB
/
lol.rb
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
require 'erb'
def get_sketch_id(file)
File.basename(file).split('.')[0].to_i
end
# we have to sort like this as we want a "natural sort" based on the actual number
# not the text of the filename
sketches = Dir.glob("sketches/*.md").sort_by{|file| get_sketch_id(file) }.reverse
# ERB template for the main page
#
main_template = ERB.new <<-EOF
<html>
<head>
<title>RC Creative Coding Archive</title>
<meta charset="utf-8"/>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link rel="stylesheet" href="/styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>🐙 RC Creative Coding Archive 👋</h1>
<p>This is an archive of creative coding things folks at RC have done (or found)! Please enjoy and share</p>
<p>
<a href="https://github.com/ukd1/rc-creative-coding/issues/new">Add something!</a>
—
<a href="https://www.recurse.com/calendar/21866">Join us</a>
—
<a href="https://github.com/ukd1/rc-creative-coding">The code</a>
—
<a href="https://www.recurse.com">Recurse Center</a>
</p>
<br>
<%= sketches_html %>
<script>
marked.setOptions({gfm: true, breaks: true});
document.querySelectorAll('.md').forEach((block) => {
block.innerHTML = marked.parse(block.innerHTML);
});
</script>
</body>
</html>
EOF
# ERB template for the individual sketchs
#
sketch_template = ERB.new <<-EOF
<div id="sketch_<%= id %>">
<h2><%= file %></h2> <a href='#sketch_<%= id %>'>🔗</a>
<div class='md'><%= File.read(file) %></div>
<br>
</div>
EOF
# map over each sketch
sketches_html = sketches.map do |file|
id = get_sketch_id(file)
# and render the template...
sketch_template.result(binding)
end.join("\n") # then join each sketch by new lines... 😅
# just puts the output, as we're prolly just gonna write to a file
puts main_template.result(binding)