-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from camya/feature/robots-tag-support
Robots Tag feature (+ pest tests + documentation)
- Loading branch information
Showing
15 changed files
with
226 additions
and
47 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
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 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 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 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 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 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 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 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 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,29 @@ | ||
<?php | ||
|
||
namespace RalphJSmit\Laravel\SEO\Tags; | ||
|
||
use Illuminate\Contracts\Support\Renderable; | ||
use Illuminate\Support\Collection; | ||
use RalphJSmit\Laravel\SEO\Support\MetaTag; | ||
use RalphJSmit\Laravel\SEO\Support\RenderableCollection; | ||
use RalphJSmit\Laravel\SEO\Support\SEOData; | ||
|
||
class RobotsTag extends Collection implements Renderable | ||
{ | ||
use RenderableCollection; | ||
|
||
public static function initialize(SEOData $SEOData = null): static | ||
{ | ||
$collection = new static(); | ||
|
||
$robotsContent = config('seo.robots.default'); | ||
|
||
if ( ! config('seo.robots.force_default') ) { | ||
$robotsContent = $SEOData?->robots ?? $robotsContent; | ||
} | ||
|
||
$collection->push(new MetaTag('robots', $robotsContent)); | ||
|
||
return $collection; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace RalphJSmit\Laravel\SEO\Tags; | ||
|
||
use Illuminate\Contracts\Support\Renderable; | ||
use Illuminate\Support\Collection; | ||
use RalphJSmit\Laravel\SEO\Support\RenderableCollection; | ||
use RalphJSmit\Laravel\SEO\Support\SEOData; | ||
use RalphJSmit\Laravel\SEO\Support\SitemapTag as SitemapTagSupport; | ||
|
||
class SitemapTag extends Collection implements Renderable | ||
{ | ||
use RenderableCollection; | ||
|
||
public static function initialize(SEOData $SEOData = null): static | ||
{ | ||
$collection = new static(); | ||
|
||
if ( $sitemap = config('seo.sitemap') ) { | ||
$collection->push(new SitemapTagSupport($sitemap)); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Str; | ||
|
||
use function Pest\Laravel\get; | ||
|
||
it('can display the canonical URL if allowed', function () { | ||
config()->set('seo.canonical_link', true); | ||
|
||
get($url = route('seo.test-plain', ['name' => 'robots'])) | ||
->assertSee('<link rel="canonical" href="' . Str::before($url, '?name') . '">', false); | ||
}); | ||
|
||
it('cannot display the canonical url if not allowed', function () { | ||
config()->set('seo.canonical_link', false); | ||
|
||
get($url = route('seo.test-plain', ['name' => 'robots'])) | ||
->assertDontSee('rel="canonical"', false); | ||
}); | ||
|
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,69 @@ | ||
<?php | ||
|
||
use RalphJSmit\Laravel\SEO\Support\SEOData; | ||
use RalphJSmit\Laravel\SEO\Tests\Fixtures\Page; | ||
|
||
use function Pest\Laravel\get; | ||
use function Pest\Laravel\post; | ||
|
||
it('can output the robots tag "default" value', function () { | ||
config()->set('seo.robots.default', 'max-snippet:-1'); | ||
|
||
get($url = route('seo.test-plain')) | ||
->assertSee('<meta name="robots" content="max-snippet:-1">', false); | ||
}); | ||
|
||
it('can overwrite the robots tag "default" value with the robots attribute (SEOData)', function () { | ||
config()->set('seo.robots.default', 'max-snippet:-1'); | ||
config()->set('seo.robots.force_default', false); | ||
|
||
$SEOData = new SEOData( | ||
robots: 'noindex,nofollow', | ||
); | ||
$SEODataOutput = (string) seo($SEOData); | ||
|
||
$this->assertStringContainsString('<meta name="robots" content="noindex,nofollow">', $SEODataOutput); | ||
}); | ||
|
||
it('cannot overwrite the robots tag "default" value with the robots attribute if "force_default" is set (SEOData)', function () { | ||
config()->set('seo.robots.default', 'max-snippet:-1'); | ||
config()->set('seo.robots.force_default', true); | ||
|
||
$SEOData = new SEOData( | ||
robots: 'noindex,nofollow', | ||
); | ||
$SEODataOutput = (string) seo($SEOData); | ||
|
||
$this->assertStringContainsString('<meta name="robots" content="max-snippet:-1">', $SEODataOutput); | ||
}); | ||
|
||
it('can overwrite the robots tag "default" value with the robots attribute (DB Model)', function () { | ||
config()->set('seo.robots.default', 'max-snippet:-1'); | ||
|
||
$page = Page::create(); | ||
|
||
$page->seo->update([ | ||
'robots' => 'noindex,nofollow', | ||
]); | ||
|
||
$page->refresh(); | ||
|
||
get(route('seo.test-page', ['page' => $page])) | ||
->assertSee('<meta name="robots" content="noindex,nofollow">', false); | ||
}); | ||
|
||
it('cannot overwrite the robots tag "default" value with the robots attribute if "force_default" is set (DB Model)', function () { | ||
config()->set('seo.robots.default', 'max-snippet:-1'); | ||
config()->set('seo.robots.force_default', true); | ||
|
||
$page = Page::create(); | ||
|
||
$page->seo->update([ | ||
'robots' => 'noindex,nofollow', | ||
]); | ||
|
||
$page->refresh(); | ||
|
||
get(route('seo.test-page', ['page' => $page])) | ||
->assertSee('<meta name="robots" content="max-snippet:-1">', false); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.