9 use function file_put_contents
;
11 require_once $_composer_autoload_path ?? __DIR__
."/../vendor/autoload.php";
13 define("ROOT", dirname(__DIR__
));
14 define("REF2HTML", true);
17 fprintf(STDERR
, "Usage: %s <basedir> <ref>[ <ref> ...]\n", $argv[0]);
18 fprintf(STDERR
, " Note: the basedir will also be used as <base href>\n");
21 function say($fmt, ...$args) {
22 return fprintf(STDERR
, $fmt, ...$args);
25 if (!is_dir($out) && !mkdir($out, 0775, true)) {
26 fprintf(STDERR
, "Could not create output directory %s\n", $out);
29 $nul = fopen("/dev/null", "w");
30 $url = new BaseUrl("/" . $out . "/");
33 $ref = new Reference(array_slice($argv, 2));
34 $fmt = function(string $src, string $dst) use($ref, $out, $nul, $url) {
36 $req->setRequestMethod("GET");
37 $req->setRequestUrl($url . "./" . $src);
39 $res->setBody(new Body(fopen($dst, "w+")));
40 $act = new Action($ref, $req, $res, $url, $nul);
44 "php/PropertyProxy" => "propro/php/PropertyProxy",
45 "pq/Gateway" => "pq-gateway/pq/Gateway",
46 "pq/Query" => "pq-gateway/pq/Query",
48 $red = function($from, $dest, $name) use($out, $url) {
49 $from = $out . "/" . str_replace($dest, $from, $name);
50 if (!is_dir(dirname($from))) {
51 mkdir(dirname($from), 0775, true);
53 file_put_contents($from . ".html", <<<EOF
55 <meta http-equiv='refresh' content='0; $url$name'>
60 $gen = function(Entry
$entry) use($fmt, $out, $xfm, $red, &$gen) {
61 $src = $entry->getName();
62 $dir = $out . "/" . $src;
63 $dst = $dir . ".html";
64 foreach ($xfm as $from => $dest) {
65 if (strpos($src, $dest) !== false) {
66 say("Redirecting from %s to %s\n", $from, $dest);
67 $red($from, $dest, $src);
71 if ($entry->hasIterator()) {
73 mkdir($dir, 0755, true);
75 foreach ($entry as $subentry) {
79 say("Generating %s from %s\n", $dst, $src);
82 /** @var $repo Repo */
83 foreach ($ref as $repo) {
84 say("Entering ref %s\n", $repo->getName());
85 if (is_file($stub = $repo->getPath($repo->getName().".stub.php"))) {
86 copy($stub, $out . "/" . basename($stub));
88 foreach ($repo as $root) {
92 $fmt("", $out . "/" . "index.html");
98 "public/index.css" => "index.css",
99 "public/index.js" => "index.js",
100 "public/favicon.ico" => "favicon.ico",
102 foreach ($presets as $src => $dst) {
103 if (!is_string($src)) {
106 copy(ROOT
. "/" . $src, $out . "/" . $dst);
109 touch($out . "/.nojekyll");
110 // htacess for apache
111 file_put_contents($out . "/.htaccess", <<<EOF
112 Options -Indexes +MultiViews +FollowSymLinks
116 RewriteCond %{REQUEST_FILENAME} -d
117 RewriteRule ^(.+)$ $1.html [L]
121 SetHandler default-handler