From 3b9fa57f0875720c75b093e391012a90c50c954e Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 11 Oct 2016 23:38:05 +0200 Subject: * subdirectories allowed in static pages paths --- bin/static-site.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/static-site.php b/bin/static-site.php index 8b76555..eaa18a4 100755 --- a/bin/static-site.php +++ b/bin/static-site.php @@ -94,11 +94,29 @@ if ($indexTemplate === FALSE) { $filesToRender = ['index.html' => $indexTemplates[$indexTemplate], '404.html' => '../404.tpl']; -$directory = opendir($templateDirectory); -while ($file = readdir($directory)) { +$contentTemplateCommand = sprintf( + 'find %s -name \*.tpl', + escapeshellarg($templateDirectory) +); +$contentTemplates = array_filter( + explode( + PHP_EOL, + shell_exec($contentTemplateCommand) + ) +); +foreach ($contentTemplates as $file) { $fileMatch = array(); - if (preg_match('/^(.*)\.tpl$/', $file, $fileMatch)) { - $filesToRender[$fileMatch[1] . DIRECTORY_SEPARATOR . 'index.html'] = $file; + if (preg_match(sprintf( + '#^%s\/(.*\.tpl)$#', + preg_quote($templateDirectory) + ), $file, $fileMatch)) { + $filesToRender[ + preg_replace( + '/\.tpl$/', + DIRECTORY_SEPARATOR . 'index.html', + $fileMatch[1] + ) + ] = $fileMatch[1]; } } @@ -179,7 +197,7 @@ foreach ($filesToRender as $output => $template) { array_slice(explode(DIRECTORY_SEPARATOR, $outputPath), 0, -1) ); if (!is_dir($outputDir)) { - mkdir($outputDir); + mkdir($outputDir, 0777, TRUE); } file_put_contents($outputPath, $renderer->fetch('index.tpl')); -- cgit v1.2.3