From f903b0060c473753d79a88d3067c513f1f364a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Sun, 19 Jul 2015 23:17:57 +0200 Subject: [PATCH] Fix index pages detection in live mode --- libs/Daux.php | 4 +--- libs/Format/Base/LiveGenerator.php | 3 ++- libs/Format/HTML/Template.php | 2 +- libs/Generator/Command.php | 3 ++- libs/Server/Server.php | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/Daux.php b/libs/Daux.php index da32b42..c654ba2 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -69,8 +69,6 @@ class Daux //config.json $this->loadConfigOverrides($override_file); - - $this->generateTree(); } /** @@ -145,7 +143,7 @@ class Daux /** * Generate the tree that will be used */ - private function generateTree() + public function generateTree() { $this->tree = new Root($this->getParams(), $this->docs_path); Builder::build($this->tree, $this->options['ignore']); diff --git a/libs/Format/Base/LiveGenerator.php b/libs/Format/Base/LiveGenerator.php index eedaea7..6c49f42 100644 --- a/libs/Format/Base/LiveGenerator.php +++ b/libs/Format/Base/LiveGenerator.php @@ -3,7 +3,8 @@ use Todaymade\Daux\Config; use Todaymade\Daux\Tree\Entry; -interface LiveGenerator { +interface LiveGenerator +{ /** * @param Entry $node * @param Config $params diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index ef27ab0..484a360 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -96,7 +96,7 @@ class Template foreach ($tree->getEntries() as $node) { $url = $node->getUri(); if ($node instanceof Content) { - if ($node->getName() === '_index') { + if (in_array($node->getName(), ['index', '_index'])) { continue; } diff --git a/libs/Generator/Command.php b/libs/Generator/Command.php index d301a4f..312df2c 100644 --- a/libs/Generator/Command.php +++ b/libs/Generator/Command.php @@ -33,7 +33,8 @@ class Command extends SymfonyCommand // Instiantiate the processor if one is defined $this->prepareProcessor($daux, $input, $output, $width); - // Improve the tree with a processor + // Generate the tree + $daux->generateTree(); $daux->getProcessor()->manipulateTree($daux->tree); // Set the format if requested diff --git a/libs/Server/Server.php b/libs/Server/Server.php index b5992a6..bf98728 100644 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -5,7 +5,6 @@ use Todaymade\Daux\Daux; use Todaymade\Daux\DauxHelper; use Todaymade\Daux\Exception; use Todaymade\Daux\Format\Base\LiveGenerator; -use Todaymade\Daux\Format\HTML\Generator; use Todaymade\Daux\Format\HTML\RawPage; class Server @@ -23,7 +22,6 @@ class Server public static function serve() { $daux = new Daux(Daux::LIVE_MODE); - $daux->initialize(); $class = $daux->getProcessorClass(); @@ -31,14 +29,17 @@ class Server $daux->setProcessor(new $class($daux, new NullOutput(), 0)); } + // Set this critical configuration + // for the tree generation + $daux->getParams()['index_key'] = 'index'; + // Improve the tree with a processor + $daux->generateTree(); $daux->getProcessor()->manipulateTree($daux->tree); $server = new static($daux); try { - - $page = $server->handle($_REQUEST); } catch (NotFoundException $e) { http_response_code(404); @@ -85,7 +86,6 @@ class Server { $params = $this->daux->getParams(); - $params['index_key'] = 'index'; $params['host'] = $this->host; DauxHelper::rebaseConfiguration($params, '//' . $this->base_url); @@ -111,8 +111,8 @@ class Server $request = $this->getRequest(); $request = urldecode($request); - if ($request == 'first_page') { - $request = $this->daux->tree->getFirstPage()->getUri(); + if ($request == 'index_page') { + $request = $this->daux->tree->getIndexPage()->getUri(); } return $this->getPage($request); @@ -171,7 +171,7 @@ class Server } $uri = str_replace(array('//', '../'), '/', trim($uri, '/')); if ($uri == "") { - $uri = "first_page"; + $uri = "index_page"; } return $uri; }