1
0
Fork 1
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

41 lines
1.1 KiB
PHP

<?php
// Perform static site generation.
require_once "getenv.php";
// https://stackoverflow.com/a/17161106
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge(
[],
...[$files, rglob($dir . "/" . basename($pattern), $flags)]
);
}
return $files;
}
foreach (rglob("$TEMPLATES_ROOT/*.php") as $phppath) {
// Do not render auxiliary PHP files.
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$docpath = str_replace(".php", ".html", $docpath);
// This works? Yes, yes it does.
// We do this to isolate the environment and include-once triggers,
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes.
log_info("Generating output for $relpath.");
$document = `cd "$TEMPLATES_ROOT"; php $phppath`;
file_put_contents($docpath, $document);
}
log_info("Done generating HTML.");
?>