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");
22 if (!is_dir($out) && !mkdir($out, 0775, true)) {
23 fprintf(STDERR
, "Could not create output directory %s\n", $out);
26 $nul = fopen("/dev/null", "w");
27 $url = new BaseUrl("/" . $out . "/");
30 $ref = new Reference(array_slice($argv, 2));
31 $fmt = function(string $src, string $dst) use($ref, $out, $nul, $url) {
33 $req->setRequestMethod("GET");
34 $req->setRequestUrl($url . "./" . $src);
36 $res->setBody(new Body(fopen($dst, "w+")));
37 $act = new Action($ref, $req, $res, $url, $nul);
41 "php/PropertyProxy" => "propro/php/PropertyProxy",
42 "pq/Gateway" => "pq-gateway/pq/Gateway",
43 "pq/Query" => "pq-gateway/pq/Query",
45 $red = function($from, $dest, $name) use($out, $url) {
46 $from = $out . "/" . str_replace($dest, $from, $name);
47 if (!is_dir(dirname($from))) {
48 mkdir(dirname($from), 0775, true);
50 file_put_contents($from . ".html", <<<EOF
52 <meta http-equiv='refresh' content='0; $url$name'>
57 $gen = function(Entry
$entry) use($fmt, $out, $xfm, $red, &$gen) {
58 $src = $entry->getName();
59 $dir = $out . "/" . $src;
60 $dst = $dir . ".html";
61 foreach ($xfm as $from => $dest) {
62 if (strpos($src, $dest) !== false) {
63 printf("Redirecting from %s to %s\n", $from, $dest);
64 $red($from, $dest, $src);
68 if ($entry->hasIterator()) {
70 mkdir($dir, 0755, true);
72 foreach ($entry as $subentry) {
76 printf("Generating %s from %s\n", $dst, $src);
79 /** @var $repo Repo */
80 foreach ($ref as $repo) {
81 printf("Entering ref %s\n", $repo->getName());
82 if (is_file($stub = $repo->getPath($repo->getName().".stub.php"))) {
83 copy($stub, $out . "/" . basename($stub));
85 foreach ($repo as $root) {
89 $fmt("", $out . "/" . "index.html");
95 "public/index.css" => "index.css",
96 "public/index.js" => "index.js",
97 "public/favicon.ico" => "favicon.ico",
99 foreach ($presets as $src => $dst) {
100 if (!is_string($src)) {
103 copy(ROOT
. "/" . $src, $out . "/" . $dst);
106 touch($out . "/.nojekyll");
107 // htacess for apache
108 file_put_contents($out . "/.htaccess", <<<EOF
109 Options -Indexes +MultiViews +FollowSymLinks
113 RewriteCond %{REQUEST_FILENAME} -d
114 RewriteRule ^(.+)$ $1.html [L]
118 SetHandler default-handler