Skip to content

Commit

Permalink
fix: robots and sitemap served at /storage path
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara committed Nov 22, 2023
1 parent 22914fe commit 74cc74b
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/node_modules
/public/hot
/public/storage
/public/robots.txt
/public/sitemap.xml
/storage/*.key
/vendor
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ClearRobots.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class ClearRobots extends Command
*/
public function handle()
{
Storage::disk('public')->delete('robots.txt');
Storage::disk('public_root')->delete('robots.txt');
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/ClearSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class ClearSitemap extends Command
*/
public function handle()
{
Storage::disk('public')->delete('sitemap.xml');
Storage::disk('public_root')->delete('sitemap.xml');
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/GenerateRobots.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class GenerateRobots extends Command
*/
public function handle()
{
Storage::disk('public')->put('robots.txt', view('robots')->render());
Storage::disk('public_root')->put('robots.txt', view('robots')->render());
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function handle()
}
}

Storage::disk('public')->put('sitemap.xml', view('sitemap', ['routes' => $routes, 'lastmod' => $lastmod])->render());
Storage::disk('public_root')->put('sitemap.xml', view('sitemap', ['routes' => $routes, 'lastmod' => $lastmod])->render());
}
}
5 changes: 5 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
'visibility' => 'public',
],

'public_root' => [
'driver' => 'local',
'root' => public_path(),
],

'snapshots' => [
'driver' => 'local',
'root' => database_path('snapshots'),
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/Console/ClearRobotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->robots = 'robots.txt';
$this->original = 'robots.original.txt';

if ($this->disk->fileExists($this->robots)) {
Storage::disk('public')->move($this->robots, $this->original);
Storage::disk('public_root')->move($this->robots, $this->original);
}

Storage::disk('public')->put($this->robots, 'test');
Storage::disk('public_root')->put($this->robots, 'test');
});

afterEach(function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public_root')->delete($this->robots);

if ($this->disk->fileExists($this->original)) {
Storage::disk('public')->move($this->original, $this->robots);
Storage::disk('public_root')->move($this->original, $this->robots);
}
});

Expand All @@ -33,7 +33,7 @@
});

test('Clear robots.txt completes even if file did not exist', function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public_root')->delete($this->robots);
$this->disk->assertMissing($this->robots);

artisan('seo:clear-robots')->assertSuccessful();
Expand Down
22 changes: 11 additions & 11 deletions tests/Feature/Console/ClearSeoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->robots = 'robots.txt';
$this->robotsOriginal = 'robots.original.txt';
$this->sitemap = 'sitemap.xml';
$this->sitemapOriginal = 'sitemap.original.xml';

if ($this->disk->fileExists($this->robots)) {
Storage::disk('public')->move($this->robots, $this->robotsOriginal);
Storage::disk('public_root')->move($this->robots, $this->robotsOriginal);
}

if ($this->disk->fileExists($this->sitemap)) {
Storage::disk('public')->move($this->sitemap, $this->sitemapOriginal);
Storage::disk('public_root')->move($this->sitemap, $this->sitemapOriginal);
}

Storage::disk('public')->put($this->robots, 'test');
Storage::disk('public')->put($this->sitemap, '<test></test>');
Storage::disk('public_root')->put($this->robots, 'test');
Storage::disk('public_root')->put($this->sitemap, '<test></test>');
});

afterEach(function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->robots);
Storage::disk('public_root')->delete($this->sitemap);

if ($this->disk->fileExists($this->robotsOriginal)) {
Storage::disk('public')->move($this->robotsOriginal, $this->robots);
Storage::disk('public_root')->move($this->robotsOriginal, $this->robots);
}

if ($this->disk->fileExists($this->sitemapOriginal)) {
Storage::disk('public')->move($this->sitemapOriginal, $this->sitemap);
Storage::disk('public_root')->move($this->sitemapOriginal, $this->sitemap);
}
});

Expand All @@ -47,8 +47,8 @@
});

test('Clear seo completes even if files did not exist', function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->robots);
Storage::disk('public_root')->delete($this->sitemap);

$this->disk->assertMissing($this->robots);
$this->disk->assertMissing($this->sitemap);
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/Console/ClearSitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->sitemap = 'sitemap.xml';
$this->original = 'sitemap.original.xml';

if ($this->disk->fileExists($this->sitemap)) {
Storage::disk('public')->move($this->sitemap, $this->original);
Storage::disk('public_root')->move($this->sitemap, $this->original);
}

Storage::disk('public')->put($this->sitemap, '<test></test>');
Storage::disk('public_root')->put($this->sitemap, '<test></test>');
});

afterEach(function () {
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->sitemap);

if ($this->disk->fileExists($this->original)) {
Storage::disk('public')->move($this->original, $this->sitemap);
Storage::disk('public_root')->move($this->original, $this->sitemap);
}
});

Expand All @@ -33,7 +33,7 @@
});

test('Clear sitemap completes even if file did not exist', function () {
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->sitemap);
$this->disk->assertMissing($this->sitemap);

artisan('seo:clear-sitemap')->assertSuccessful();
Expand Down
27 changes: 0 additions & 27 deletions tests/Feature/Console/DeployLocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,10 @@

use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->robots = 'robots.txt';
$this->robotsOriginal = 'robots.original.txt';
$this->sitemap = 'sitemap.xml';
$this->sitemapOriginal = 'sitemap.original.xml';

if ($this->disk->fileExists($this->robots)) {
Storage::disk('public')->move($this->robots, $this->robotsOriginal);
}

if ($this->disk->fileExists($this->sitemap)) {
Storage::disk('public')->move($this->sitemap, $this->sitemapOriginal);
}
});

afterEach(function () {
artisan('optimize:clear');
artisan('icons:clear');
artisan('event:clear');

Storage::disk('public')->delete($this->robots);
Storage::disk('public')->delete($this->sitemap);

if ($this->disk->fileExists($this->robotsOriginal)) {
Storage::disk('public')->move($this->robotsOriginal, $this->robots);
}

if ($this->disk->fileExists($this->sitemapOriginal)) {
Storage::disk('public')->move($this->sitemapOriginal, $this->sitemap);
}
});

test('Completes successfully', function () {
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/Console/GenerateRobotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->robots = 'robots.txt';
$this->original = 'robots.original.txt';

if ($this->disk->fileExists($this->robots)) {
Storage::disk('public')->move($this->robots, $this->original);
Storage::disk('public_root')->move($this->robots, $this->original);
}
});

afterEach(function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public_root')->delete($this->robots);

if ($this->disk->fileExists($this->original)) {
Storage::disk('public')->move($this->original, $this->robots);
Storage::disk('public_root')->move($this->original, $this->robots);
}
});

Expand All @@ -31,7 +31,7 @@
});

test('Generate robots completes even if file already exists', function () {
Storage::disk('public')->put($this->robots, 'test');
Storage::disk('public_root')->put($this->robots, 'test');

$this->disk->assertExists($this->robots);

Expand Down
18 changes: 9 additions & 9 deletions tests/Feature/Console/GenerateSeoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->robots = 'robots.txt';
$this->robotsOriginal = 'robots.original.txt';
$this->sitemap = 'sitemap.xml';
$this->sitemapOriginal = 'sitemap.original.xml';

if ($this->disk->fileExists($this->robots)) {
Storage::disk('public')->move($this->robots, $this->robotsOriginal);
Storage::disk('public_root')->move($this->robots, $this->robotsOriginal);
}

if ($this->disk->fileExists($this->sitemap)) {
Storage::disk('public')->move($this->sitemap, $this->sitemapOriginal);
Storage::disk('public_root')->move($this->sitemap, $this->sitemapOriginal);
}
});

afterEach(function () {
Storage::disk('public')->delete($this->robots);
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->robots);
Storage::disk('public_root')->delete($this->sitemap);

if ($this->disk->fileExists($this->robotsOriginal)) {
Storage::disk('public')->move($this->robotsOriginal, $this->robots);
Storage::disk('public_root')->move($this->robotsOriginal, $this->robots);
}

if ($this->disk->fileExists($this->sitemapOriginal)) {
Storage::disk('public')->move($this->sitemapOriginal, $this->sitemap);
Storage::disk('public_root')->move($this->sitemapOriginal, $this->sitemap);
}
});

Expand All @@ -44,8 +44,8 @@
});

test('Generate seo completes even if files already exist', function () {
Storage::disk('public')->put($this->robots, 'test');
Storage::disk('public')->put($this->sitemap, '<test></test>');
Storage::disk('public_root')->put($this->robots, 'test');
Storage::disk('public_root')->put($this->sitemap, '<test></test>');

$this->disk->assertExists($this->robots);
$this->disk->assertExists($this->sitemap);
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/Console/GenerateSitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use function Pest\Laravel\artisan;

beforeEach(function () {
$this->disk = Storage::disk('public');
$this->disk = Storage::disk('public_root');
$this->sitemap = 'sitemap.xml';
$this->original = 'sitemap.original.xml';

if ($this->disk->fileExists($this->sitemap)) {
Storage::disk('public')->move($this->sitemap, $this->original);
Storage::disk('public_root')->move($this->sitemap, $this->original);
}
});

afterEach(function () {
Storage::disk('public')->delete($this->sitemap);
Storage::disk('public_root')->delete($this->sitemap);

if ($this->disk->fileExists($this->original)) {
Storage::disk('public')->move($this->original, $this->sitemap);
Storage::disk('public_root')->move($this->original, $this->sitemap);
}
});

Expand All @@ -31,11 +31,11 @@
});

test('Generate sitemaps completes even if file already exists', function () {
Storage::disk('public')->put($this->sitemap, '<test></test>');
Storage::disk('public_root')->put($this->sitemap, '<test></test>');

$this->disk->assertExists($this->sitemap);

artisan('seo:generate')->assertSuccessful();
artisan('seo:generate-sitemap')->assertSuccessful();

$this->disk->assertExists($this->sitemap);
});

0 comments on commit 74cc74b

Please sign in to comment.