mers/site/build.mers

59 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env mers
2023-05-04 05:42:45 +02:00
// helper functions
fn read_string(path string) {
bytes_to_string(fs_read(path).assume_no_enum()).assume_no_enum()
}
2023-05-04 05:42:45 +02:00
fn code_to_html(code string code_width_limit_chars int) {
out = ""
for line code.regex(".*").assume_no_enum() {
if code_width_limit_chars.gtoe(0).and(line.len().gt(code_width_limit_chars)) {
line = line.substring(0 code_width_limit_chars)
}
2023-05-04 05:42:45 +02:00
line = line
.replace("&" "&")
.replace("<" "&lt;")
.replace(">" "&gt;")
out = out.add(line.add("<br>"))
}
2023-05-04 05:42:45 +02:00
out
}
2023-05-04 05:42:45 +02:00
// data
index = read_string("index.html")
index_html = index.code_to_html(75)
build_script = read_string("build.mers").code_to_html(-1)
welcome_script = read_string("welcome.mers").code_to_html(-1)
// process index.html
out = ""
for line index.regex("\\S*.*").assume_no_enum() {
if line.starts_with("#") {
// comment, ignore
} else if line.starts_with("$") {
if line.eq("$welcome_script") {
2023-05-04 05:42:45 +02:00
out = out.add(welcome_script)
} else if line.eq("$build_script") {
out = out.add(build_script)
} else if line.eq("$index.html") {
out = out.add(index_html)
}
} else {
2023-05-04 05:42:45 +02:00
// remove spaces
loop {
if line.starts_with(" ") {
line = line.substring(1)
} else {
true // break
}
}
out = out.add(line.add("\n"))
}
}
fs_write("../index.html" string_to_bytes(out)).assume_no_enum()