From c8be03c8c0ca127831e0cd3ec59ab28f83564fe0 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Wed, 8 Jan 2020 10:45:00 -0700 Subject: [PATCH] Enabled README rendering control via config --- .env.example | 2 ++ app/Controllers/DirectoryController.php | 14 +++++++++----- app/config/app.php | 14 +++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 1f4e252..26d7a05 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app/Controllers/DirectoryController.php b/app/Controllers/DirectoryController.php index eeae838..af9669b 100644 --- a/app/Controllers/DirectoryController.php +++ b/app/Controllers/DirectoryController.php @@ -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); } } diff --git a/app/config/app.php b/app/config/app.php index 0786586..11d4d7c 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -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. *