Merge pull request #299 from holodyn/dev_inherit_index

Added inherit_index feature
This commit is contained in:
Stéphane Goetz 2015-08-02 14:58:59 +02:00
commit 27e0e8780c
4 changed files with 48 additions and 0 deletions

View File

@ -236,6 +236,17 @@ 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.
```json
{
"live": [
"inherit_index": true
]
}
```
###Multi-language ###Multi-language
Enables multi-language support which needs seperate directories for each language in `docs/` folder. Enables multi-language support which needs seperate directories for each language in `docs/` folder.

View File

@ -8,6 +8,7 @@
"folders": ["99_Not_Ready"] "folders": ["99_Not_Ready"]
}, },
"live": { "live": {
"inherit_index": true,
"clean_urls": true "clean_urls": true
}, },
"html": { "html": {

View File

@ -18,6 +18,7 @@
"timezone": "America/Los_Angeles", "timezone": "America/Los_Angeles",
"live": { "live": {
"inherit_index": false,
"clean_urls": false "clean_urls": false
}, },

View File

@ -54,9 +54,44 @@ class Directory extends Entry
return $this->children[$index_key]; return $this->children[$index_key];
} }
/*
If the inherit_index flag is set, then we seek child content
*/
if(
!empty($this->getConfig()['live']['inherit_index'])
&& $first_page = $this->seekFirstPage()
){
return $first_page;
}
return null; return null;
} }
/**
* Seek the first available page from descendants
* @return Content|null
*/
public function seekFirstPage(){
if( $this instanceof Directory ){
$index_key = $this->getConfig()['index_key'];
if (isset($this->children[$index_key])) {
return $this->children[$index_key];
}
foreach( $this->children AS $node_key => $node ){
if( $node instanceof Content ){
return $node;
}
if(
$node instanceof Directory
&& strpos($node->getUri(), '.') !== 0
&& $childNode = $node->seekFirstPage() ){
return $childNode;
}
}
}
return null;
}
/** /**
* @return Content|null * @return Content|null
*/ */