Fixed base url problems in live mode
This commit is contained in:
parent
1f167db1f6
commit
f757e88040
@ -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,6 +167,7 @@ class Daux
|
|||||||
*/
|
*/
|
||||||
public function getParams()
|
public function getParams()
|
||||||
{
|
{
|
||||||
|
if (!$this->merged_defaults) {
|
||||||
$default = [
|
$default = [
|
||||||
//Features
|
//Features
|
||||||
'multilanguage' => !empty($this->options['languages']),
|
'multilanguage' => !empty($this->options['languages']),
|
||||||
@ -174,7 +181,13 @@ class Daux
|
|||||||
];
|
];
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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(),
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user