Fixed base url problems in live mode

This commit is contained in:
Stéphane Goetz 2015-07-19 14:05:12 +02:00
parent 1f167db1f6
commit f757e88040
4 changed files with 44 additions and 37 deletions

View File

@ -33,6 +33,12 @@ class Daux
/** @var string */ /** @var string */
private $mode; private $mode;
/** @var bool */
private $merged_defaults = false;
/** @var bool */
private $merged_tree = false;
/** /**
* @param string $mode * @param string $mode
*/ */
@ -161,20 +167,27 @@ class Daux
*/ */
public function getParams() public function getParams()
{ {
$default = [ if (!$this->merged_defaults) {
//Features $default = [
'multilanguage' => !empty($this->options['languages']), //Features
'multilanguage' => !empty($this->options['languages']),
//Paths and tree //Paths and tree
'theme-name' => $this->options['theme'], 'theme-name' => $this->options['theme'],
'mode' => $this->mode, 'mode' => $this->mode,
'local_base' => $this->local_base, 'local_base' => $this->local_base,
'docs_path' => $this->docs_path, 'docs_path' => $this->docs_path,
'templates' => $this->internal_base . DS . 'templates', 'templates' => $this->internal_base . DS . 'templates',
]; ];
$this->options->conservativeMerge($default); $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['tree'] = $this->tree;
$this->options['index'] = $this->tree->getIndexPage() ?: $this->tree->getFirstPage(); $this->options['index'] = $this->tree->getIndexPage() ?: $this->tree->getFirstPage();
if ($this->options['multilanguage']) { if ($this->options['multilanguage']) {
@ -184,11 +197,9 @@ class Daux
} else { } else {
$this->options['entry_page'] = $this->tree->getFirstPage(); $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; return $this->options;
} }

View File

@ -4,6 +4,19 @@ use Todaymade\Daux\Tree\Directory;
class DauxHelper 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>', $base_url, $config['image']);
}
/** /**
* @param Config $params * @param Config $params
* @param string $current_url * @param string $current_url

View File

@ -54,19 +54,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
$this->generateRecursive($this->daux->tree, $destination, $params, $output, $width); $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>', $base_url, $config['image']);
}
/** /**
* Recursively generate the documentation * 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 = '') 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'])) { if ($base_url !== '' && empty($params['entry_page'])) {
$params['entry_page'] = $tree->getFirstPage(); $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); $this->generateRecursive($node, $new_output_dir, $params, $output, $width, '../' . $base_url);
// Rebase configuration again as $params is a shared object // Rebase configuration again as $params is a shared object
$this->rebaseConfig($params, $base_url); DauxHelper::rebaseConfiguration($params, $base_url);
} else { } else {
$this->runAction( $this->runAction(
"- " . $node->getUrl(), "- " . $node->getUrl(),

View File

@ -74,17 +74,13 @@ class Server
$params['index_key'] = 'index'; $params['index_key'] = 'index';
$params['host'] = $this->host; $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']) { if (!$this->daux->options['clean_urls']) {
$params['base_page'] .= 'index.php/'; $params['base_page'] .= 'index.php/';
} }
if ($params['image'] !== '') {
$params['image'] = str_replace('<base_url>', $params['base_url'], $params['image']);
}
$params['theme'] = DauxHelper::getTheme($params, $this->base_url);
return $params; return $params;
} }