Skip to content

Commit

Permalink
feat: allow robots to crawl (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Feb 18, 2024
1 parent 9a6d843 commit fc4ac77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion public/robots.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
User-agent: *
Disallow:
Disallow: /register
Disallow: /login
Disallow: /forgot-password
Disallow: /reset-password
Allow: /
Sitemap: /sitemap/sitemap.xml

0 comments on commit fc4ac77

Please sign in to comment.