diff --git a/libs/Daux.php b/libs/Daux.php index f113b9a..c1bef29 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -33,6 +33,12 @@ class Daux /** @var string */ private $mode; + /** @var bool */ + private $merged_defaults = false; + + /** @var bool */ + private $merged_tree = false; + /** * @param string $mode */ @@ -161,20 +167,27 @@ class Daux */ public function getParams() { - $default = [ - //Features - 'multilanguage' => !empty($this->options['languages']), + if (!$this->merged_defaults) { + $default = [ + //Features + 'multilanguage' => !empty($this->options['languages']), - //Paths and tree - 'theme-name' => $this->options['theme'], - 'mode' => $this->mode, - 'local_base' => $this->local_base, - 'docs_path' => $this->docs_path, - 'templates' => $this->internal_base . DS . 'templates', - ]; - $this->options->conservativeMerge($default); + //Paths and tree + 'theme-name' => $this->options['theme'], + 'mode' => $this->mode, + 'local_base' => $this->local_base, + 'docs_path' => $this->docs_path, + 'templates' => $this->internal_base . DS . 'templates', + ]; + $this->options->conservativeMerge($default); - if ($this->tree) { + $this->options['index_key'] = 'index.html'; + $this->options['base_page'] = $this->options['base_url'] = ''; + + $this->merged_defaults = true; + } + + if ($this->tree && !$this->merged_tree) { $this->options['tree'] = $this->tree; $this->options['index'] = $this->tree->getIndexPage() ?: $this->tree->getFirstPage(); if ($this->options['multilanguage']) { @@ -184,11 +197,9 @@ class Daux } else { $this->options['entry_page'] = $this->tree->getFirstPage(); } + $this->merged_tree = true; } - $this->options['index_key'] = 'index.html'; - $this->options['base_page'] = $this->options['base_url'] = ''; - return $this->options; } diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index 53aa390..b28d1aa 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -4,6 +4,19 @@ use Todaymade\Daux\Tree\Directory; class DauxHelper { + public static function rebaseConfiguration(Config $config, $base_url) + { + // Avoid changing the url if it is already correct + if ($config['base_url'] == $base_url && !empty($config['theme']) && !is_string($config['theme'])) { + return; + } + + // Change base url for all links on the pages + $config['base_url'] = $config['base_page'] = $base_url; + $config['theme'] = static::getTheme($config, $base_url); + $config['image'] = str_replace('', $base_url, $config['image']); + } + /** * @param Config $params * @param string $current_url diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 6b237b0..62dab63 100644 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -54,19 +54,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->generateRecursive($this->daux->tree, $destination, $params, $output, $width); } - private function rebaseConfig(Config $config, $base_url) - { - // Avoid changing the url if it is already correct - if ($config['base_url'] == $base_url && !empty($config['theme']) && !is_string($config['theme'])) { - return; - } - - // Change base url for all links on the pages - $config['base_url'] = $config['base_page'] = $base_url; - $config['theme'] = DauxHelper::getTheme($config, $base_url); - $config['image'] = str_replace('', $base_url, $config['image']); - } - /** * Recursively generate the documentation * @@ -80,7 +67,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator */ private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, $base_url = '') { - $this->rebaseConfig($params, $base_url); + DauxHelper::rebaseConfiguration($params, $base_url); if ($base_url !== '' && empty($params['entry_page'])) { $params['entry_page'] = $tree->getFirstPage(); @@ -93,7 +80,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->generateRecursive($node, $new_output_dir, $params, $output, $width, '../' . $base_url); // Rebase configuration again as $params is a shared object - $this->rebaseConfig($params, $base_url); + DauxHelper::rebaseConfiguration($params, $base_url); } else { $this->runAction( "- " . $node->getUrl(), diff --git a/libs/Server/Server.php b/libs/Server/Server.php index 9902cc0..509dec8 100644 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -74,17 +74,13 @@ class Server $params['index_key'] = 'index'; $params['host'] = $this->host; - $params['base_page'] = $params['base_url'] = '//' . $this->base_url; + + DauxHelper::rebaseConfiguration($params, '//' . $this->base_url); + $params['base_page'] = '//' . $this->base_url; if (!$this->daux->options['clean_urls']) { $params['base_page'] .= 'index.php/'; } - if ($params['image'] !== '') { - $params['image'] = str_replace('', $params['base_url'], $params['image']); - } - - $params['theme'] = DauxHelper::getTheme($params, $this->base_url); - return $params; }