Added the inherit_index feature for routing requests to directories without a valid index defined.
This commit is contained in:
parent
c6d6634857
commit
7a01df7ea9
11
README.md
11
README.md
@ -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.
|
||||||
|
|
||||||
|
@ -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": {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"timezone": "America/Los_Angeles",
|
"timezone": "America/Los_Angeles",
|
||||||
|
|
||||||
"live": {
|
"live": {
|
||||||
|
"inherit_index": false,
|
||||||
"clean_urls": false
|
"clean_urls": false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -54,6 +54,43 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user