Added the inherit_index feature for routing requests to directories without a valid index defined.

This commit is contained in:
David Hunt 2015-07-21 14:34:21 -04:00
parent c6d6634857
commit 7a01df7ea9
4 changed files with 50 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
Enables multi-language support which needs seperate directories for each language in `docs/` folder.

View File

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

View File

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

View File

@ -54,9 +54,46 @@ class Directory extends Entry
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;
}
/**
* 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
){
if( $node->seekFirstPage() ){
return $node->seekFirstPage();
}
}
}
}
return null;
}
/**
* @return Content|null
*/