Implement SSG for non-HTML & subfolders

dev
gravel 7 months ago
parent bbad3a1ebb
commit 33f1f863e9
Signed by: gravel
GPG Key ID: C0538F3C906B308F

1
.gitignore vendored

@ -3,6 +3,7 @@ output/servers.json
# Generated HTML
output/*.html
output/**/*.html
# Downloaded QR codes
output/qr-codes

@ -23,9 +23,9 @@
}
/**
* Generate HTML from PHP files in the templates directory.
* Generate files from PHP templates in the templates directory.
*/
function generate_html() {
function generate_files() {
global $LOGGING_VERBOSITY, $TEMPLATES_ROOT, $DOCUMENT_ROOT;
$flags = LoggingVerbosity::getVerbosityFlags($LOGGING_VERBOSITY)[1];
@ -35,14 +35,21 @@
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
$filename = basename($phppath);
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$docpath = str_replace(".php", ".html", $docpath);
$dirname = dirname($relpath);
if (preg_match("/[^.]+\\.\w+\\.php$/", $filename) == 1) {
$docpath = str_replace(".php", "", $docpath);
} else {
$docpath = str_replace(".php", ".html", $docpath);
}
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
mkdir("$DOCUMENT_ROOT/$dirname", recursive: true);
log_info("Generating output for $relpath.");
$output = [];
@ -51,7 +58,7 @@
exec("cd '$TEMPLATES_ROOT'; php '$phppath' $flags", $output, $exit_code);
if ($exit_code != 0 || empty($output)) {
log_error("HTML generation failed.");
log_error("Site generation failed.");
exit(255);
}
@ -60,8 +67,8 @@
file_put_contents($docpath, join("\n", $output));
}
log_info("Done generating HTML.");
log_info("Done generating site.");
}
generate_html();
generate_files();
?>

Loading…
Cancel
Save