Make build script that parses and copies files

This commit is contained in:
Reimar 2024-03-16 14:17:04 +01:00
parent 55c64e6758
commit e78eda7e4c
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
5 changed files with 118 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
public/src/

55
build.php Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env php
<?php
$dir = new RecursiveDirectoryIterator("temple-src");
$iterator = new RecursiveIteratorIterator($dir);
$matches = new RegexIterator($iterator, "/^.+\.(DD|HC)$/i", RecursiveRegexIterator::GET_MATCH);
foreach ($matches as $match) {
$file = $match[0];
$content = file_get_contents($file);
$filename = basename($file);
$bodyclass = "BG-15 FG-0 ";
if (str_contains($content, '$WW,1$')) {
$bodyclass .= "word-wrap";
}
$content = htmlentities($content, ENT_NOQUOTES); // Escape HTML
$content = nl2br($content, false); // Use <br> for newlines
$content = str_replace("\u{5}", "", $content); // Remove cursor position
$content = preg_replace('/\$(FG|BG),(\d+)\$(.+?)\$FG\$/s', '<span class="$1-$2">$3</span>', $content); // Foreground / background color
$content = preg_replace('/\$LK,"([^"]+?)",A="(FI:)?::(.+?)"\$/s', '<a href="/src$3.HTML">$1</a>', $content); // File links
$content = preg_replace('/\$LK,"([^"]+?)",A="FF:::(.+?),(.+?)"\$/s', '<a href="/src$2.HTML#$3">$1</a>', $content); // File links with search
$content = preg_replace('/\$LK,"([^"]+?)",A="(MN|HI):(.+?)"\$/s', '<a href="#" onclick="alert(\'This type of link is not implemented yet\')">$1</a>', $content); // Unimplemented links
$content = preg_replace('/\$LK,"(FI:)?::(.+?)"\$/s', '<a href="/src$2.HTML">$2</a>', $content); // File links without title
$content = preg_replace('/\$ID,(\d+)\$(.+?)\$ID,-\1\$/s', '<div style="margin-left: $1ch;">$2</div>', $content); // Indentation
$content = preg_replace('/\$\$/', '&#36;', $content); // Escaping dollar signs
$content = preg_replace('/\$TX\+CX,"(.+?)"\$/s', '<center>$1</center>', $content); // Centered text
$content = preg_replace('/\$TX\+RX,"(.+?)"\$/s', '<div style="text-align: right;">$1</div>', $content); // Right-justified text
$content = preg_replace('/\$UL,1\$(.+?)\$UL,0\$/s', '<u>$1</u>', $content); // Underlined text
$content = preg_replace('/\$IV,1\$(.+?)\$IV,0\$/s', '<span class="invert">$1</span>', $content); // Inverted text
$content = preg_replace('/\$BK,1\$(.+?)\$BK,0\$/s', '<span class="blink">$1</span>', $content); // Blinking text
$content = preg_replace('/\$SY,(-?\d+)\$(.+?)\$SY,0\$/s', '<span style="position: relative; top: $1px;">$2</span>', $content); // Shift-y
$content = preg_replace('/\$WW.+?\$/', "", $content); // Word wrap
$content = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>$filename</title>
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js" defer></script>
</head>
<body class="$bodyclass">
$content
</body>
</html>
HTML;
$newfile = str_replace("temple-src/", "/public/src/", $file) . ".HTML";
if (!is_dir(__DIR__ . dirname($newfile))) mkdir(__DIR__ . dirname($newfile), 0755, true);
file_put_contents(__DIR__ . $newfile, $content);
}

12
public/index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>TempleOS</title>
</head>
<body>
<h1>TempleOS</h1>
<h2>Documentation</h2>
</body>
</html>

View File

@ -0,0 +1,6 @@
// Blink elements
[].forEach.call(document.getElementsByClassName("blink"), function (elem) {
setInterval(function () {
elem.classList.toggle("invert");
}, 200);
});

43
public/style/templeos.css Normal file
View File

@ -0,0 +1,43 @@
body {
font-family: monospace;
font-weight: bold;
}
a {
color: #A00;
}
.FG-0, .BG-0 .invert { color: #000; }
.FG-1, .BG-1 .invert { color: #00A; }
.FG-2, .BG-2 .invert { color: #0A0; }
.FG-3, .BG-3 .invert { color: #0AA; }
.FG-4, .BG-4 .invert { color: #A00; }
.FG-5, .BG-5 .invert { color: #A0A; }
.FG-6, .BG-6 .invert { color: #A50; }
.FG-7, .BG-7 .invert { color: #AAA; }
.FG-8, .BG-8 .invert { color: #555; }
.FG-9, .BG-9 .invert { color: #55F; }
.FG-10, .BG-10 .invert { color: #5F5; }
.FG-11, .BG-11 .invert { color: #5FF; }
.FG-12, .BG-12 .invert { color: #F55; }
.FG-13, .BG-13 .invert { color: #F5F; }
.FG-14, .BG-14 .invert { color: #FF5; }
.FG-15, .BG-15 .invert { color: #FFF; }
.BG-0, .FG-0 .invert { background-color: #000; }
.BG-1, .FG-1 .invert { background-color: #00A; }
.BG-2, .FG-2 .invert { background-color: #0A0; }
.BG-3, .FG-3 .invert { background-color: #0AA; }
.BG-4, .FG-4 .invert { background-color: #A00; }
.BG-5, .FG-5 .invert { background-color: #A0A; }
.BG-6, .FG-6 .invert { background-color: #A50; }
.BG-7, .FG-7 .invert { background-color: #AAA; }
.BG-8, .FG-8 .invert { background-color: #555; }
.BG-9, .FG-9 .invert { background-color: #55F; }
.BG-10, .FG-10 .invert { background-color: #5F5; }
.BG-11, .FG-11 .invert { background-color: #5FF; }
.BG-12, .FG-12 .invert { background-color: #F55; }
.BG-13, .FG-13 .invert { background-color: #F5F; }
.BG-14, .FG-14 .invert { background-color: #FF5; }
.BG-15, .FG-15 .invert { background-color: #FFF; }