9 use function file_put_contents
;
11 require_once __DIR__
."/../vendor/autoload.php";
12 define("ROOT", dirname(__DIR__
));
13 define("REF2HTML", true);
16 fprintf(STDERR
, "Usage: %s <basedir> <ref>[ <ref> ...]\n", $argv[0]);
17 fprintf(STDERR
, " Note: the basedir will also be used as <base href>\n");
20 function say($fmt, ...$args) {
21 return fprintf(STDERR
, $fmt, ...$args);
24 if (!is_dir($out) && !mkdir($out, 0775, true)) {
25 fprintf(STDERR
, "Could not create output directory %s\n", $out);
28 $nul = fopen("/dev/null", "w");
29 $url = new BaseUrl("/" . $out . "/");
32 $ref = new Reference(array_slice($argv, 2));
33 $fmt = function(string $src, string $dst) use($ref, $out, $nul, $url) {
35 $req->setRequestMethod("GET");
36 $req->setRequestUrl($url . "./" . $src);
38 $res->setBody(new Body(fopen($dst, "w+")));
39 $act = new Action($ref, $req, $res, $url, $nul);
43 "php/PropertyProxy" => "propro/php/PropertyProxy",
44 "pq/Gateway" => "pq-gateway/pq/Gateway",
45 "pq/Query" => "pq-gateway/pq/Query",
47 $red = function($from, $dest, $name) use($out, $url) {
48 $from = $out . "/" . str_replace($dest, $from, $name);
49 if (!is_dir(dirname($from))) {
50 mkdir(dirname($from), 0775, true);
52 file_put_contents($from . ".html", <<<EOF
54 <meta http-equiv='refresh' content='0; $url$name'>
59 $gen = function(Entry
$entry) use($fmt, $out, $xfm, $red, &$gen) {
60 $src = $entry->getName();
61 $dir = $out . "/" . $src;
62 $dst = $dir . ".html";
63 foreach ($xfm as $from => $dest) {
64 if (strpos($src, $dest) !== false) {
65 say("Redirecting from %s to %s\n", $from, $dest);
66 $red($from, $dest, $src);
70 if ($entry->hasIterator()) {
72 mkdir($dir, 0755, true);
74 foreach ($entry as $subentry) {
78 say("Generating %s from %s\n", $dst, $src);
81 /** @var $repo Repo */
82 foreach ($ref as $repo) {
83 say("Entering ref %s\n", $repo->getName());
84 if (is_file($stub = $repo->getPath($repo->getName().".stub.php"))) {
85 copy($stub, $out . "/" . basename($stub));
87 foreach ($repo as $root) {
91 $fmt("", $out . "/" . "index.html");
97 "public/index.css" => "index.css",
98 "public/index.js" => "index.js",
99 "public/favicon.ico" => "favicon.ico",
101 foreach ($presets as $src => $dst) {
102 if (!is_string($src)) {
105 copy(ROOT
. "/" . $src, $out . "/" . $dst);
108 touch($out . "/.nojekyll");
109 // htacess for apache
110 file_put_contents($out . "/.htaccess", <<<EOF
111 Options -Indexes +MultiViews +FollowSymLinks
115 RewriteCond %{REQUEST_FILENAME} -d
116 RewriteRule ^(.+)$ $1.html [L]
120 SetHandler default-handler