Skip to content

Commit

Permalink
Fix the URL Generator for inherit_index, fixes #381
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Aug 2, 2016
1 parent c450903 commit 647c0be
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"folders": ["99_Not_Ready"]
},
"live": {
"inherit_index": true,
"clean_urls": true
},
"html": {
Expand All @@ -18,6 +17,7 @@
"toggle_code": true,
"date_modified": true,
"float": true,
"inherit_index": true,

"repo": "justinwalsh/daux.io",
"twitter": ["justin_walsh", "todaymade"],
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"timezone": "America/Los_Angeles",

"live": {
"inherit_index": false,
"clean_urls": false
},

Expand All @@ -32,6 +31,7 @@
"auto_landing": true,
"search": true,
"auto_toc": false,
"inherit_index": false,

"repo": "",
"twitter": [],
Expand Down
13 changes: 13 additions & 0 deletions libs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 2 additions & 6 deletions libs/Format/HTML/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions libs/Tree/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 647c0be

Please sign in to comment.