-
Notifications
You must be signed in to change notification settings - Fork 11
/
combine.raku
executable file
·62 lines (47 loc) · 2.02 KB
/
combine.raku
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
#!/usr/bin/env raku
use YAMLish;
my %toc = load-yaml('_data/toc.yaml'.IO.slurp);
my $root = '_site';
my $out = '';
for %toc<toc><> -> %part {
$out ~= "\n\n<h1>{%part<title>}</h1>\n\n";
for %part<items><> -> %subpart {
$out ~= "\n\n<h1>{%subpart<title>}</h1>\n\n";
for %subpart<items><> -> %section {
# $out ~= "\n\n<h2>{%section<title>}</h2>\n\n";
$out ~= content("$root/%part<url>/%section<url>/index.html");
if %section<quizzes>:exists {
for %section<quizzes><> -> %quiz {
# $out ~= "\n\n<h4>{%quiz<title>}</h4>\n\n";
$out ~= content("$root/%part<url>/%section<url>/%quiz<url>/index.html");;
}
}
if %section<items>:exists {
for %section<items><> -> %topic {
# $out ~= "\n\n<h3>{%topic<title>}</h3>\n\n";
$out ~= content("$root/%part<url>/%section<url>/%topic<url>/index.html");
if %topic<quizzes>:exists {
for %topic<quizzes><> -> %quiz {
$out ~= "\n\n<h4>{%quiz<title>}</h4>\n\n";
$out ~= content("$root/%part<url>/%section<url>/%topic<url>/%quiz<url>/index.html");;
}
}
}
}
if %section<exercises>:exists {
for %section<exercises><> -> %exercise {
# $out ~= "\n\n<h4>{%exercise<title>}</h4>\n\n";
$out ~= content("$root/%part<url>/%section<url>/exercises/%exercise<url>/index.html");
# $out ~= "\n\n<h4>Solution: {%exercise<title>}</h4>\n\n";
$out ~= content("$root/%part<url>/%section<url>/exercises/%exercise<url>/solution/index.html");
}
}
}
}
}
$out.say;
sub content($path) {
my $html = $path.IO.slurp;
$html ~~ /('<h1' .*? '>' .* )'<h2 id="course-navigation">Course navigation</h2>'/;
return ~$/[0];
}