Enabled README rendering control via config

This commit is contained in:
Chris Kankiewicz
2020-01-08 10:45:00 -07:00
parent d0e0a80ada
commit c8be03c8c0
3 changed files with 18 additions and 12 deletions

View File

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

View File

@@ -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);
}
}

View File

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