-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sitemap generation command and update related files; modify robot…
…s.txt and site manifest for SEO improvements
- Loading branch information
1 parent
c7431be
commit 5e2bf9e
Showing
7 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Homestead.yaml | |
auth.json | ||
npm-debug.log | ||
yarn-error.log | ||
/public/sitemap.xml | ||
/.fleet | ||
/.idea | ||
/.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Spatie\Sitemap\SitemapGenerator; | ||
use Spatie\Sitemap\Tags\Url; | ||
use Psr\Http\Message\UriInterface; | ||
use Illuminate\Support\Str; | ||
|
||
|
||
class GenerateSitemap extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'generate-sitemap'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Crawl the site to generate a sitemap.xml file'; | ||
|
||
|
||
private array $noIndexPaths = [ | ||
'', | ||
'/forum/*', | ||
'/login/github', | ||
'/user/*', | ||
]; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
SitemapGenerator::create(config('app.url')) | ||
->shouldCrawl(function (UriInterface $url) { | ||
return $this->shouldIndex($url->getPath()); | ||
}) | ||
->hasCrawled(function (Url $url) { | ||
if ($this->shouldNotIndex($url->path())) { | ||
return; | ||
} | ||
|
||
return $url; | ||
}) | ||
->writeToFile(public_path('sitemap.xml')); | ||
|
||
$this->info('Sitemap generated'); | ||
} | ||
|
||
private function shouldNotIndex(string $path): bool | ||
{ | ||
return Str::is($this->noIndexPaths, $path); | ||
} | ||
|
||
private function shouldIndex(string $path): bool | ||
{ | ||
return ! $this->shouldNotIndex($path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<browserconfig> | ||
<msapplication> | ||
<tile> | ||
<square150x150logo src="/web-app-manifest-192x192.png"/> | ||
<TileColor>#2b5797</TileColor> | ||
</tile> | ||
</msapplication> | ||
</browserconfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
User-agent: * | ||
Allow: / | ||
Sitemap: https://laravel-starter.com/sitemap.xml | ||
Disallow: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters