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.
sessioncommunities.online/php/generate-html.php

34 lines
999 B
PHTML

<?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 auxilliary PHP files.
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_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.
2 years ago
$document = `php $phppath`; // should be identical to shell_exec("php $phppath")
file_put_contents($docpath, $document);
}
2 years ago
?>