summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-10-11 23:38:05 +0200
committeremkael <emkael@tlen.pl>2016-10-11 23:38:05 +0200
commit3b9fa57f0875720c75b093e391012a90c50c954e (patch)
treec9efbe8e3ad40aa265758185dab3ab5a5cccaf7f /bin
parent8827cdf8dcf5efbdc8b35cbdb621459e8a182214 (diff)
* subdirectories allowed in static pages paths
Diffstat (limited to 'bin')
-rwxr-xr-xbin/static-site.php28
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'));