From fc4ac778b9ee4ce6ac1d715556101a9839b80279 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 18 Feb 2024 23:31:29 +0100 Subject: [PATCH] feat: allow robots to crawl (#49) --- app/Console/Commands/GenerateSitemap.php | 6 ++++++ public/robots.txt | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/GenerateSitemap.php b/app/Console/Commands/GenerateSitemap.php index 71cb7ea..6583c19 100644 --- a/app/Console/Commands/GenerateSitemap.php +++ b/app/Console/Commands/GenerateSitemap.php @@ -5,6 +5,7 @@ use App\Models\Name; use Illuminate\Console\Command; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\SitemapGenerator; @@ -44,6 +45,11 @@ public function handle(): void $this->sitemap_names($sitemapIndex); $sitemapIndex->writeToFile(public_path(static::PREFIX_PATH . '/sitemap.xml')); + + // Replace sitemap in robots.txt + $robots = File::get(public_path('robots.txt')); + $robots = Str::of($robots)->replaceMatches('/Sitemap: .*/', 'Sitemap: ' . url(static::PREFIX_PATH . '/sitemap.xml')); + File::put(public_path('robots.txt'), $robots); } /** diff --git a/public/robots.txt b/public/robots.txt index 0ee2e08..18da568 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,3 +1,7 @@ User-agent: * -Disallow: +Disallow: /register +Disallow: /login +Disallow: /forgot-password +Disallow: /reset-password +Allow: / Sitemap: /sitemap/sitemap.xml