From 1a72208d27e1b27034fd9eb5f657d6f3cd0c5ad7 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 31 Mar 2018 12:41:40 +0100 Subject: [PATCH] Added configurable robots.txt file. Deleted old static file. Default output depends on app-public setting. Otherwise can be overidden in `.env` file via `ALLOW_ROBOTS` Otherwise view file can be customized. Fixes #779 --- app/Http/Controllers/HomeController.php | 16 +++++++++++++ config/app.php | 16 +++++++++++++ public/robots.txt | 2 -- resources/views/robots.blade.php | 6 +++++ routes/web.php | 1 + tests/PublicActionTest.php | 31 +++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) delete mode 100644 public/robots.txt create mode 100644 resources/views/robots.blade.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3a5fd2cb5..bbe1a8679 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -118,4 +118,20 @@ class HomeController extends Controller { return view('partials/custom-head-content'); } + + /** + * Show the view for /robots.txt + * @return $this + */ + public function getRobots() + { + $sitePublic = setting('app-public', false); + $allowRobots = config('app.allow_robots'); + if ($allowRobots === null) { + $allowRobots = $sitePublic; + } + return response() + ->view('robots', ['allowRobots' => $allowRobots]) + ->header('Content-Type', 'text/plain'); + } } diff --git a/config/app.php b/config/app.php index fad0c20f2..ca30ee2a0 100755 --- a/config/app.php +++ b/config/app.php @@ -4,12 +4,28 @@ return [ 'env' => env('APP_ENV', 'production'), + /** + * Set the default view type for various lists. Can be overridden by user preferences. + * This will be used for public viewers and users that have not set a preference. + */ 'views' => [ 'books' => env('APP_VIEWS_BOOKS', 'list') ], + /** + * Allow