2015-04-22 12:23:57 +02:00
|
|
|
<?php namespace Todaymade\Daux\Generator;
|
|
|
|
|
|
|
|
use Todaymade\Daux\Daux;
|
2015-04-23 15:47:05 +02:00
|
|
|
use Todaymade\Daux\DauxHelper;
|
2015-04-22 12:23:57 +02:00
|
|
|
use Todaymade\Daux\MarkdownPage;
|
2015-04-22 18:24:10 +02:00
|
|
|
use Todaymade\Daux\Tree\Directory;
|
|
|
|
use Todaymade\Daux\Tree\Content;
|
2015-04-22 12:23:57 +02:00
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
class Generator
|
|
|
|
{
|
|
|
|
public function generate($global_config, $destination)
|
|
|
|
{
|
2015-04-22 12:23:57 +02:00
|
|
|
$daux = new Daux(Daux::STATIC_MODE);
|
|
|
|
$daux->initialize($global_config);
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
$params = $daux->getParams();
|
|
|
|
if (is_null($destination)) {
|
|
|
|
$destination = $daux->local_base . DS . 'static';
|
|
|
|
}
|
2015-04-22 12:23:57 +02:00
|
|
|
|
2015-04-23 15:47:05 +02:00
|
|
|
echo "Copying Static assets ...\n";
|
2015-04-23 00:32:30 +02:00
|
|
|
Helper::copyAssets($destination, $daux->local_base);
|
|
|
|
|
2015-04-23 15:47:05 +02:00
|
|
|
echo "Generating ...\n";
|
2015-04-23 00:32:30 +02:00
|
|
|
$this->generateRecursive($daux->tree, $destination, $params);
|
2015-04-23 15:47:05 +02:00
|
|
|
echo "Done !\n";
|
2015-04-22 12:23:57 +02:00
|
|
|
}
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
private function generateRecursive($tree, $output_dir, $params, $base_url = '')
|
|
|
|
{
|
2015-04-22 12:23:57 +02:00
|
|
|
$params['base_url'] = $params['base_page'] = $base_url;
|
2015-04-23 15:47:05 +02:00
|
|
|
|
|
|
|
// Rebase Theme
|
|
|
|
$params['theme'] = DauxHelper::getTheme(
|
2015-04-23 21:04:00 +02:00
|
|
|
$params['theme-name'],
|
|
|
|
$params['base_url'],
|
2015-04-23 15:47:05 +02:00
|
|
|
$params['local_base'],
|
2015-04-23 21:04:00 +02:00
|
|
|
$base_url
|
2015-04-23 15:47:05 +02:00
|
|
|
);
|
|
|
|
|
2015-04-22 12:23:57 +02:00
|
|
|
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
|
2015-04-23 00:32:30 +02:00
|
|
|
if ($base_url !== '') {
|
|
|
|
$params['entry_page'] = $tree->getFirstPage();
|
|
|
|
}
|
2015-04-22 12:23:57 +02:00
|
|
|
foreach ($tree->value as $key => $node) {
|
2015-04-22 18:24:10 +02:00
|
|
|
if ($node instanceof Directory) {
|
2015-04-23 00:32:30 +02:00
|
|
|
$new_output_dir = $output_dir . DS . $key;
|
2015-04-22 12:23:57 +02:00
|
|
|
@mkdir($new_output_dir);
|
2015-04-23 15:47:05 +02:00
|
|
|
$this->generateRecursive($node, $new_output_dir, $params, '../' . $base_url);
|
2015-04-23 00:32:30 +02:00
|
|
|
} elseif ($node instanceof Content) {
|
2015-04-23 15:47:05 +02:00
|
|
|
echo "- " . $node->getUrl() . "\n";
|
2015-04-23 00:32:30 +02:00
|
|
|
$params['request'] = $node->getUrl();
|
|
|
|
$params['file_uri'] = $node->getName();
|
2015-04-22 12:23:57 +02:00
|
|
|
|
|
|
|
$page = MarkdownPage::fromFile($node, $params);
|
2015-04-23 00:32:30 +02:00
|
|
|
file_put_contents($output_dir . DS . $key, $page->getContent());
|
2015-04-22 18:24:10 +02:00
|
|
|
} else {
|
2015-04-23 15:47:05 +02:00
|
|
|
echo "- " . $node->getUrl() . "\n";
|
2015-04-23 00:32:30 +02:00
|
|
|
copy($node->getPath(), $output_dir . DS . $key);
|
2015-04-22 12:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|