diff options
Diffstat (limited to 'bin/static-site.php')
-rwxr-xr-x | bin/static-site.php | 28 |
1 files changed, 23 insertions, 5 deletions
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')); |