2015-04-22 12:23:57 +02:00
|
|
|
<?php namespace Todaymade\Daux\Generator;
|
|
|
|
|
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
use Todaymade\Daux\Entry;
|
|
|
|
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
|
|
|
|
|
|
|
class Generator {
|
|
|
|
public function generate($global_config, $destination) {
|
|
|
|
$daux = new Daux(Daux::STATIC_MODE);
|
|
|
|
$daux->initialize($global_config);
|
|
|
|
|
|
|
|
$this->generate_static($daux, $destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generate_static(Daux $daux, $output_dir = NULL) {
|
|
|
|
$params = $daux->get_page_params();
|
|
|
|
if (is_null($output_dir)) $output_dir = $daux->local_base . DIRECTORY_SEPARATOR . 'static';
|
|
|
|
Helper::clean_copy_assets($output_dir, $daux->local_base);
|
|
|
|
$this->recursive_generate_static($daux->tree, $output_dir, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function recursive_generate_static($tree, $output_dir, $params, $base_url = '') {
|
|
|
|
$params['base_url'] = $params['base_page'] = $base_url;
|
|
|
|
$new_params = $params;
|
|
|
|
//
|
|
|
|
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
|
|
|
|
if ($base_url !== '') $params['entry_page'] = $tree->first_page;
|
|
|
|
foreach ($tree->value as $key => $node) {
|
2015-04-22 18:24:10 +02:00
|
|
|
if ($node instanceof Directory) {
|
2015-04-22 12:23:57 +02:00
|
|
|
$new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key;
|
|
|
|
@mkdir($new_output_dir);
|
|
|
|
$this->recursive_generate_static($node, $new_output_dir, $new_params, '../' . $base_url);
|
2015-04-22 18:24:10 +02:00
|
|
|
} else if ($node instanceof Content) {
|
2015-04-22 12:23:57 +02:00
|
|
|
$params['request'] = $node->get_url();
|
|
|
|
$params['file_uri'] = $node->name;
|
|
|
|
|
|
|
|
$page = MarkdownPage::fromFile($node, $params);
|
|
|
|
file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $page->get_page_content());
|
2015-04-22 18:24:10 +02:00
|
|
|
} else {
|
|
|
|
copy($node->local_path, $output_dir . DIRECTORY_SEPARATOR . $key);
|
2015-04-22 12:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|