diff --git a/rebuild.cmd b/rebuild.cmd index dc2fc94..25facc0 100644 --- a/rebuild.cmd +++ b/rebuild.cmd @@ -1,5 +1,7 @@ @echo off +set PHP=C:\bin\php54\php.exe + echo Cleaning target directory... echo. rmdir /s /q wwwroot @@ -9,6 +11,10 @@ copy static\* wwwroot echo Building pages... echo. -C:\bin\php54\php.exe rebuild.php +%PHP% rebuild.php 4 0 +%PHP% rebuild.php 4 1 +%PHP% rebuild.php 4 2 +%PHP% rebuild.php 4 3 +%PHP% rebuild.php 4 4 pause \ No newline at end of file diff --git a/rebuild.php b/rebuild.php index 009cfb1..65b0359 100644 --- a/rebuild.php +++ b/rebuild.php @@ -112,6 +112,17 @@ function text2html($sz) { return nl2br($base); } +function array_decimate($array, $total, $partno) { + $ct = 0; + $ret = []; + foreach($array as $k => $v) { + if (++$ct % $total == ($partno - 1)) { + $ret[$k] = $v; + } + } + return $ret; +} + /** * */ @@ -149,7 +160,8 @@ class CProject { $this->tags = array_map('trim', explode(',', $matches[1])); } - $this->shortdesc = array_shift(explode("\n", $this->longdesc)); + $parts = explode("\n", $this->longdesc); + $this->shortdesc = array_shift($parts); $this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase continue; } @@ -162,6 +174,18 @@ class CProject { } } + public function genHomeImage() { + if (count($this->images)) { + + $this->homeimage = mkthumbnail( + $this->dir.$this->images[0], //BASEDIR.'wwwroot/srv/'.$this->projname.'_0.'.str_ext($this->images[0]), + null, // raw handle + INDEX_THUMB_W, INDEX_THUMB_H + ); + } + + } + public function write() { // Generate image thumbnails @@ -173,14 +197,6 @@ class CProject { mkthumbnail($outfile.'.'.str_ext($image), $outfile.'_thumb.jpg', PAGE_THUMB_W, PAGE_THUMB_H); } - if (count($this->images)) { - $this->homeimage = mkthumbnail( - BASEDIR.'wwwroot/srv/'.$this->projname.'_0.'.str_ext($this->images[0]), - null, // raw handle - INDEX_THUMB_W, INDEX_THUMB_H - ); - } - // Copy downloads to wwwroot foreach($this->downloads as $idx => $filename) { @@ -276,8 +292,7 @@ function template($title, $content) { return ob_get_clean(); } -function buildall() { - +function listprojects() { // List projects $ls = scandir(BASEDIR.'data'); @@ -291,21 +306,40 @@ function buildall() { $projects[$dirname] = $matches[1]; } } + + return $projects; +} + +function buildprojects($id, $projects) { + $count = 0; + + foreach($projects as $dirname => $projectname) { + + echo sprintf("@%1d [%3d/%3d] ".$projectname."...\n", $id, ++$count, count($projects)); + + $pr = new CProject($dirname, $projectname); + $pr->write(); + } +} + +function buildcommon() { + + echo "@0 [ 0/ ?] Common files...\n"; + + $projects = listprojects(); // Build all projects $plist = array(); - $count = 0; $handles = array(); $handle_lookup = array(); foreach($projects as $dirname => $projectname) { - echo sprintf("[%3d/%3d] ".$projectname."...", ++$count, count($projects)); - - $pr = new CProject($dirname, $projectname); - $pr->write(); + $pr = new CProject($dirname, $projectname); + $pr->genHomeImage(); // thumbnail + $plist[] = $pr; if (is_null($pr->homeimage)) { @@ -314,9 +348,7 @@ function buildall() { $handle_lookup[$projectname] = count($handles); $handles[] = $pr->homeimage; } - - echo " done\n"; - } + } // Build homepage spritesheet @@ -364,9 +396,25 @@ function buildall() { $index = template(SITE_TITLE, ob_get_clean()); file_put_contents(BASEDIR.'wwwroot/index.html', $index); - - echo "All processes complete.\n"; - + + // Done } -buildall(); +function main($args) { + $total = $args[0]; + $pos = $args[1]; + + if ($pos == 0) { + buildcommon(); + } else { + buildprojects($pos, array_decimate(listprojects(), $total, $pos)); + } +} + +// Entry point +// + +ini_set('display_errors', 'On'); +error_reporting(E_ALL); + +main(array_slice($_SERVER['argv'], 1));