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
bovenliggende d2b45a845f 551e03dc93
commit 27e0e8780c
4 gewijzigde bestanden met toevoegingen van 48 en 0 verwijderingen

Bestand weergeven

@ -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.

Bestand weergeven

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

Bestand weergeven

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

Bestand weergeven

@ -54,9 +54,44 @@ 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
&& $childNode = $node->seekFirstPage() ){
return $childNode;
}
}
}
return null;
}
/**
* @return Content|null
*/