From 647c0beb3b344ab009936ae402e24b6f65b8b147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Tue, 2 Aug 2016 23:39:57 +0200 Subject: [PATCH] Fix the URL Generator for inherit_index, fixes #381 --- README.md | 4 ++-- docs/config.json | 2 +- global.json | 2 +- libs/Config.php | 13 +++++++++++++ libs/Format/HTML/Template.php | 8 ++------ libs/Tree/Directory.php | 8 +------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 9ec4ce3e..0646e02e 100755 --- a/README.md +++ b/README.md @@ -266,11 +266,11 @@ If your server does not have a default timezone set in php.ini, it may return er ``` ###Inherit Index -This feature will insruct the router to seek the first available file to use when a request to a folder is made and the index is not found. +This feature will instructs the navigation generator to seek the first available file to use when there is no index in a folder. ```json { - "live": { + "html": { "inherit_index": true } } diff --git a/docs/config.json b/docs/config.json index 745e912b..34a01d78 100644 --- a/docs/config.json +++ b/docs/config.json @@ -8,7 +8,6 @@ "folders": ["99_Not_Ready"] }, "live": { - "inherit_index": true, "clean_urls": true }, "html": { @@ -18,6 +17,7 @@ "toggle_code": true, "date_modified": true, "float": true, + "inherit_index": true, "repo": "justinwalsh/daux.io", "twitter": ["justin_walsh", "todaymade"], diff --git a/global.json b/global.json index 6c93a792..36339483 100644 --- a/global.json +++ b/global.json @@ -19,7 +19,6 @@ "timezone": "America/Los_Angeles", "live": { - "inherit_index": false, "clean_urls": false }, @@ -32,6 +31,7 @@ "auto_landing": true, "search": true, "auto_toc": false, + "inherit_index": false, "repo": "", "twitter": [], diff --git a/libs/Config.php b/libs/Config.php index 57a50b19..f9e60f75 100644 --- a/libs/Config.php +++ b/libs/Config.php @@ -87,4 +87,17 @@ public function isMultilanguage() { return array_key_exists('languages', $this) && !empty($this['languages']); } + + public function shouldInheritIndex() + { + if (array_key_exists('html', $this) && array_key_exists('inherit_index', $this['html'])) { + return $this['html']['inherit_index']; + } + + if (array_key_exists('live', $this) && array_key_exists('inherit_index', $this['live'])) { + return $this['live']['inherit_index']; + } + + return false; + } } diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index e8454016..dd245c8f 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -133,12 +133,8 @@ private function buildNavigation(Directory $tree, $path, $current_url, $base_pag 'class' => strpos($current_url, $link) === 0 ? 'Nav__item--open' : '', ]; - if ($mode === Daux::STATIC_MODE) { - $link .= '/index.html'; - } - - if ($node->getIndexPage()) { - $folder['href'] = $base_page . $link; + if ($index = $node->getIndexPage()) { + $folder['href'] = $base_page . $index->getUrl(); } //Child pages diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index 88b987d3..461befcb 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -120,13 +120,7 @@ public function getIndexPage() return $this->children[$index_key]; } - /* - If the inherit_index flag is set, then we seek child content - */ - if ($this->getConfig()['mode'] == Daux::LIVE_MODE - && !empty($this->getConfig()['live']['inherit_index']) - && $first_page = $this->seekFirstPage() - ) { + if ($this->getConfig()->shouldInheritIndex() && $first_page = $this->seekFirstPage()) { return $first_page; }