mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-09-02 18:33:04 +02:00
Enabled README rendering control via config
This commit is contained in:
@@ -6,6 +6,8 @@ REVERSE_SORT=false
|
||||
HIDE_APP_FILES=true
|
||||
HIDE_VCS_FILES=true
|
||||
|
||||
DISPLAY_READMES=false
|
||||
|
||||
DATE_FORMAT="Y-m-d H:i:s"
|
||||
|
||||
MAX_HASH_SIZE=1000000000
|
||||
|
@@ -107,6 +107,10 @@ class DirectoryController
|
||||
*/
|
||||
protected function readme($path): ?SplFileInfo
|
||||
{
|
||||
if (! $this->config->get('display_readmes', false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$readmes = Finder::create()->in($path)->depth(0)->name('/^README(?:\..+)?$/i');
|
||||
$readmes->filter(function (SplFileInfo $file) {
|
||||
return (bool) preg_match('/text\/.+/', mime_content_type($file->getPathname()));
|
||||
@@ -115,12 +119,12 @@ class DirectoryController
|
||||
return $file1->getExtension() <=> $file2->getExtension();
|
||||
});
|
||||
|
||||
if ($readmes->hasResults()) {
|
||||
$readmeArray = iterator_to_array($readmes);
|
||||
|
||||
return array_shift($readmeArray);
|
||||
if (! $readmes->hasResults()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
$readmeArray = iterator_to_array($readmes);
|
||||
|
||||
return array_shift($readmeArray);
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,13 @@ return [
|
||||
*/
|
||||
'hide_vcs_files' => Helpers::env('HIDE_VSC_FILES'),
|
||||
|
||||
/**
|
||||
* Parse and render README files on the page.
|
||||
*
|
||||
* Default value: false
|
||||
*/
|
||||
'display_readmes' => Helpers::env('DISPLAY_READMES'),
|
||||
|
||||
/**
|
||||
* The maximum file size (in bytes) that can be hashed. This helps to
|
||||
* prevent timeouts for excessively large files.
|
||||
@@ -50,13 +57,6 @@ return [
|
||||
*/
|
||||
'max_hash_size' => Helpers::env('MAX_HASH_SIZE'),
|
||||
|
||||
/**
|
||||
* Parse and render README files inline.
|
||||
*
|
||||
* Default value: true
|
||||
*/
|
||||
'render_readme' => Helpers::env('RENDER_README', true),
|
||||
|
||||
/**
|
||||
* Additional providers to be loaded during application initialization.
|
||||
*
|
||||
|
Reference in New Issue
Block a user