Fixed base url problems in live mode
This commit is contained in:
bovenliggende
1f167db1f6
commit
f757e88040
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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>', $base_url, $config['image']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $params
|
||||
* @param string $current_url
|
||||
|
@ -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>', $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(),
|
||||
|
@ -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('<base_url>', $params['base_url'], $params['image']);
|
||||
}
|
||||
|
||||
$params['theme'] = DauxHelper::getTheme($params, $this->base_url);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
Laden…
Verwijs in nieuw issue
Block a user