mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
58 lines
1.5 KiB
Plaintext
Executable File
58 lines
1.5 KiB
Plaintext
Executable File
#!/usr/bin/env mers
|
|
|
|
// helper functions
|
|
|
|
fn read_string(path string) {
|
|
bytes_to_string(fs_read(path).assume_no_enum()).assume_no_enum()
|
|
}
|
|
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)
|
|
}
|
|
&line = line
|
|
.replace("&" "&")
|
|
.replace("<" "<")
|
|
.replace(">" ">")
|
|
&out = out.add(line.add("<br>"))
|
|
}
|
|
out
|
|
}
|
|
|
|
// 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 == "$welcome_script" {
|
|
&out = out + welcome_script
|
|
} else if line == "$build_script" {
|
|
&out = out + build_script
|
|
} else if line == "$index.html" {
|
|
&out = out + index_html
|
|
}
|
|
} else {
|
|
// remove spaces
|
|
loop {
|
|
if line.starts_with(" ") {
|
|
&line = line.substring(1)
|
|
} else {
|
|
true // break
|
|
}
|
|
}
|
|
&out = out + line + "\n"
|
|
}
|
|
}
|
|
fs_write("../index.html" string_to_bytes(out)).assume_no_enum()
|