mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 09:54:03 +00:00
Merge branch 'archtechx:master' into with-url-origin
This commit is contained in:
commit
85e5acb064
9 changed files with 56 additions and 56 deletions
|
|
@ -140,8 +140,8 @@ To add more tags to the document head, you can use the `tag()` and `rawTag()` me
|
|||
|
||||
```php
|
||||
seo()->tag('fb:image', asset('foo'));
|
||||
seo()->rawTag('<meta property="fb:url" content="bar" />');
|
||||
seo()->rawTag('fb_url', '<meta property="fb:url" content="bar" />'); // Keyed, allows overrides later on
|
||||
seo()->rawTag('<meta property="fb:url" content="bar">');
|
||||
seo()->rawTag('fb_url', '<meta property="fb:url" content="bar">'); // Keyed, allows overrides later on
|
||||
```
|
||||
|
||||
### Canonical URL
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<meta name="twitter:card" content="summary_large_image">
|
||||
@if(seo('twitter.creator')) <meta name="twitter:creator" content="@seo('twitter.creator')" /> @endif
|
||||
@if(seo('twitter.site')) <meta name="twitter:site" content="@seo('twitter.site')" /> @endif
|
||||
@if(seo('twitter.title')) <meta name="twitter:title" content="@seo('twitter.title')" /> @endif
|
||||
@if(seo('twitter.description')) <meta name="twitter:description" content="@seo('twitter.description')" /> @endif
|
||||
@if(seo('twitter.image')) <meta name="twitter:image" content="@seo('twitter.image')" /> @endif
|
||||
@if(seo('twitter.creator')) <meta name="twitter:creator" content="@seo('twitter.creator')"> @endif
|
||||
@if(seo('twitter.site')) <meta name="twitter:site" content="@seo('twitter.site')"> @endif
|
||||
@if(seo('twitter.title')) <meta name="twitter:title" content="@seo('twitter.title')"> @endif
|
||||
@if(seo('twitter.description')) <meta name="twitter:description" content="@seo('twitter.description')"> @endif
|
||||
@if(seo('twitter.image')) <meta name="twitter:image" content="@seo('twitter.image')"> @endif
|
||||
|
|
|
|||
|
|
@ -3,34 +3,34 @@
|
|||
|
||||
@unless(seo()->hasTag('og:title'))
|
||||
{{-- If an og:title tag is provided directly, it's included in the @foreach below --}}
|
||||
<meta property="og:title" content="@seo('title')" />
|
||||
<meta property="og:title" content="@seo('title')">
|
||||
@endunless
|
||||
@endif
|
||||
|
||||
@if(seo('description'))
|
||||
<meta property="og:description" content="@seo('description')" />
|
||||
<meta name="description" content="@seo('description')" />
|
||||
<meta property="og:description" content="@seo('description')">
|
||||
<meta name="description" content="@seo('description')">
|
||||
@endif
|
||||
|
||||
@if(seo('keywords'))
|
||||
<meta name="keywords" content="@seo('keywords')" />
|
||||
<meta name="keywords" content="@seo('keywords')">
|
||||
@endif
|
||||
|
||||
@if(seo('type'))
|
||||
<meta property="og:type" content="@seo('type')" />
|
||||
<meta property="og:type" content="@seo('type')">
|
||||
@else
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:type" content="website">
|
||||
@endif
|
||||
|
||||
@if(seo('site')) <meta property="og:site_name" content="@seo('site')" /> @endif
|
||||
@if(seo('site')) <meta property="og:site_name" content="@seo('site')"> @endif
|
||||
|
||||
@if(seo('locale')) <meta property="og:locale" content="@seo('locale')" /> @endif
|
||||
@if(seo('locale')) <meta property="og:locale" content="@seo('locale')"> @endif
|
||||
|
||||
@if(seo('image')) <meta property="og:image" content="@seo('image')" /> @endif
|
||||
@if(seo('image')) <meta property="og:image" content="@seo('image')"> @endif
|
||||
|
||||
@if(seo('url'))
|
||||
<meta property="og:url" content="@seo('url')" />
|
||||
<link rel="canonical" href="@seo('url')" />
|
||||
<meta property="og:url" content="@seo('url')">
|
||||
<link rel="canonical" href="@seo('url')">
|
||||
@endif
|
||||
|
||||
@foreach(seo()->tags() as $tag)
|
||||
|
|
|
|||
|
|
@ -9,20 +9,20 @@ use Illuminate\Support\Arr;
|
|||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @method $this title(string $title = null, ...$args) Set the title.
|
||||
* @method $this description(string $description = null, ...$args) Set the description.
|
||||
* @method $this keywords(string $keywords = null, ...$args) Set the keywords.
|
||||
* @method $this url(string $url = null, ...$args) Set the canonical URL.
|
||||
* @method $this site(string $site = null, ...$args) Set the site name.
|
||||
* @method $this image(string $url = null, ...$args) Set the cover image.
|
||||
* @method $this type(string $type = null, ...$args) Set the page type.
|
||||
* @method $this locale(string $locale = null, ...$args) Set the page locale.
|
||||
* @method $this title(?string $title = null, ...$args) Set the title.
|
||||
* @method $this description(?string $description = null, ...$args) Set the description.
|
||||
* @method $this keywords(?string $keywords = null, ...$args) Set the keywords.
|
||||
* @method $this url(?string $url = null, ...$args) Set the canonical URL.
|
||||
* @method $this site(?string $site = null, ...$args) Set the site name.
|
||||
* @method $this image(?string $url = null, ...$args) Set the cover image.
|
||||
* @method $this type(?string $type = null, ...$args) Set the page type.
|
||||
* @method $this locale(?string $locale = null, ...$args) Set the page locale.
|
||||
* @method $this twitter(bool $enabled = true, ...$args) Enable the Twitter extension.
|
||||
* @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author.
|
||||
* @method $this twitterSite(string $username = null, ...$args) Set the Twitter author.
|
||||
* @method $this twitterTitle(string $title = null, ...$args) Set the Twitter title.
|
||||
* @method $this twitterDescription(string $description = null, ...$args) Set the Twitter description.
|
||||
* @method $this twitterImage(string $url = null, ...$args) Set the Twitter cover image.
|
||||
* @method $this twitterCreator(?string $username = null, ...$args) Set the Twitter author.
|
||||
* @method $this twitterSite(?string $username = null, ...$args) Set the Twitter author.
|
||||
* @method $this twitterTitle(?string $title = null, ...$args) Set the Twitter title.
|
||||
* @method $this twitterDescription(?string $description = null, ...$args) Set the Twitter description.
|
||||
* @method $this twitterImage(?string $url = null, ...$args) Set the Twitter cover image.
|
||||
*/
|
||||
class SEOManager
|
||||
{
|
||||
|
|
@ -135,7 +135,7 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** Configure an extension. */
|
||||
public function extension(string $name, bool $enabled = true, string $view = null): static
|
||||
public function extension(string $name, bool $enabled = true, ?string $view = null): static
|
||||
{
|
||||
$this->extensions[$name] = $enabled;
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** Configure or use Flipp. */
|
||||
public function flipp(string $alias, string|array $data = null): string|static
|
||||
public function flipp(string $alias, string|array|null $data = null): string|static
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$this->meta("flipp.templates.$alias", $data);
|
||||
|
|
@ -185,7 +185,7 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** Configure or use Previewify. */
|
||||
public function previewify(string $alias, int|string|array $data = null): string|static
|
||||
public function previewify(string $alias, int|string|array|null $data = null): string|static
|
||||
{
|
||||
if (is_string($data) || is_int($data)) {
|
||||
$this->meta("previewify.templates.$alias", (string) $data);
|
||||
|
|
@ -254,7 +254,7 @@ class SEOManager
|
|||
}
|
||||
|
||||
/** Add a head tag. */
|
||||
public function rawTag(string $key, string $tag = null): static
|
||||
public function rawTag(string $key, ?string $tag = null): static
|
||||
{
|
||||
$tag ??= $key;
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ class SEOManager
|
|||
{
|
||||
$content = e($content);
|
||||
|
||||
$this->rawTag("meta.{$property}", "<meta property=\"{$property}\" content=\"{$content}\" />");
|
||||
$this->rawTag("meta.{$property}", "<meta property=\"{$property}\" content=\"{$content}\">");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -279,7 +279,7 @@ class SEOManager
|
|||
* @param string|array|null $value The value (if a single key is provided).
|
||||
* @return $this|string|null
|
||||
*/
|
||||
public function meta(string|array $key, string|array $value = null): mixed
|
||||
public function meta(string|array $key, string|array|null $value = null): mixed
|
||||
{
|
||||
if (is_array($key)) {
|
||||
/** @var array<string, string> $key */
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
use ArchTech\SEO\SEOManager;
|
||||
|
||||
if (! function_exists('seo')) {
|
||||
function seo(string|array $key = null): SEOManager|string|array|null
|
||||
function seo(string|array|null $key = null): SEOManager|string|array|null
|
||||
{
|
||||
if ($key === null) {
|
||||
return app('seo');
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ test('extensions can use custom blade paths', function () {
|
|||
|
||||
seo()->facebookTitle('abc');
|
||||
|
||||
expect(meta())->toContain('<meta name="facebook:title" content="ABC" />');
|
||||
expect(meta())->toContain('<meta name="facebook:title" content="ABC">');
|
||||
});
|
||||
|
||||
test('twitter falls back to the default values', function () {
|
||||
|
|
@ -56,7 +56,7 @@ test('twitter falls back to the default values', function () {
|
|||
expect(seo('twitter.description'))->toBe('bar');
|
||||
expect(seo('description'))->toBe('baz');
|
||||
|
||||
expect(meta())->toContain('<meta name="twitter:title" content="foo" />');
|
||||
expect(meta())->toContain('<meta name="twitter:title" content="foo">');
|
||||
});
|
||||
|
||||
test('extensions are automatically enabled when values for them are set', function () {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ test('setting the defaults returns the manager instance', function () {
|
|||
test('meta tags can be added to the template', function () {
|
||||
seo()->tag('fb:image', 'foo');
|
||||
|
||||
expect(meta())->toContain('<meta property="fb:image" content="foo" />');
|
||||
expect(meta())->toContain('<meta property="fb:image" content="foo">');
|
||||
});
|
||||
|
||||
test('raw tags can be added to the template', function () {
|
||||
|
|
@ -114,8 +114,8 @@ test('canonical url can be read from request', function () {
|
|||
seo()->withUrl();
|
||||
|
||||
expect(meta())
|
||||
->toContain('<meta property="og:url" content="http://localhost" />')
|
||||
->toContain('<link rel="canonical" href="http://localhost" />');
|
||||
->toContain('<meta property="og:url" content="http://localhost">')
|
||||
->toContain('<link rel="canonical" href="http://localhost">');
|
||||
});
|
||||
|
||||
test('canonical url accepts origin', function () {
|
||||
|
|
@ -134,8 +134,8 @@ test('canonical url can be changed', function () {
|
|||
seo()->url('http://foo.com/bar');
|
||||
|
||||
expect(meta())
|
||||
->toContain('<meta property="og:url" content="http://foo.com/bar" />')
|
||||
->toContain('<link rel="canonical" href="http://foo.com/bar" />');
|
||||
->toContain('<meta property="og:url" content="http://foo.com/bar">')
|
||||
->toContain('<link rel="canonical" href="http://foo.com/bar">');
|
||||
});
|
||||
|
||||
test('og:title can be overridden using a tag', function () {
|
||||
|
|
@ -144,16 +144,16 @@ test('og:title can be overridden using a tag', function () {
|
|||
|
||||
expect(meta())
|
||||
->toContain('<title>foo</title>')
|
||||
->toContain('<meta property="og:title" content="bar" />');
|
||||
->toContain('<meta property="og:title" content="bar">');
|
||||
});
|
||||
|
||||
test('type can be overridden using the type method', function () {
|
||||
expect(meta())->toContain('<meta property="og:type" content="website" />'); // default
|
||||
expect(meta())->toContain('<meta property="og:type" content="website">'); // default
|
||||
|
||||
seo()->type('foo');
|
||||
|
||||
expect(meta())
|
||||
->toContain('<meta property="og:type" content="foo" />') // overridden
|
||||
->toContain('<meta property="og:type" content="foo">') // overridden
|
||||
->not()->toContain('website');
|
||||
});
|
||||
|
||||
|
|
@ -165,5 +165,5 @@ test('og:locale is not included by default', function () {
|
|||
test('og:locale can be added to the template', function () {
|
||||
seo()->locale('de_DE');
|
||||
|
||||
expect(meta())->toContain('<meta property="og:locale" content="de_DE" />');
|
||||
expect(meta())->toContain('<meta property="og:locale" content="de_DE">');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ test('opengraph methods properly sanitize input', function (string $method, stri
|
|||
expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters </title> " . \' ."');
|
||||
expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\"");
|
||||
|
||||
expect($meta)->toContain("<meta property=\"$property\" content=\"{$sanitizedContent}\" />");
|
||||
expect($meta)->toContain("<meta property=\"$property\" content=\"Testing string " with several ' XSS characters </title> " . ' .\" />");
|
||||
expect($meta)->toContain("<meta property=\"$property\" content=\"{$sanitizedContent}\">");
|
||||
expect($meta)->toContain("<meta property=\"$property\" content=\"Testing string " with several ' XSS characters </title> " . ' .\">");
|
||||
})->with([
|
||||
['site', 'og:site_name'],
|
||||
['url', 'og:url'],
|
||||
|
|
@ -37,8 +37,8 @@ test('the twitter extension properly sanitizes input', function (string $method,
|
|||
expect($meta)->not()->toContain('content="Testing string " with several \' XSS characters </title> " . \' ."');
|
||||
expect($meta)->not()->toContain("content=\"{$unsanitizedContent}\"");
|
||||
|
||||
expect($meta)->toContain("<meta name=\"$property\" content=\"{$sanitizedContent}\" />");
|
||||
expect($meta)->toContain("<meta name=\"$property\" content=\"Testing string " with several ' XSS characters </title> " . ' .\" />");
|
||||
expect($meta)->toContain("<meta name=\"$property\" content=\"{$sanitizedContent}\">");
|
||||
expect($meta)->toContain("<meta name=\"$property\" content=\"Testing string " with several ' XSS characters </title> " . ' .\">");
|
||||
})->with([
|
||||
['twitterCreator', 'twitter:creator'],
|
||||
['twitterSite', 'twitter:site'],
|
||||
|
|
@ -65,8 +65,8 @@ test('the title method properly sanitizes both tags', function () {
|
|||
|
||||
expect($meta)->toContain("<title>{$sanitizedContent}</title>");
|
||||
expect($meta)->toContain("<title>Testing string " with several ' XSS characters </title> " . ' .</title>");
|
||||
expect($meta)->toContain("<meta property=\"og:title\" content=\"{$sanitizedContent}\" />");
|
||||
expect($meta)->toContain("<meta property=\"og:title\" content=\"Testing string " with several ' XSS characters </title> " . ' .\" />");
|
||||
expect($meta)->toContain("<meta property=\"og:title\" content=\"{$sanitizedContent}\">");
|
||||
expect($meta)->toContain("<meta property=\"og:title\" content=\"Testing string " with several ' XSS characters </title> " . ' .\">");
|
||||
});
|
||||
|
||||
test('seo blade directive calls are sanitized', function () {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<meta name="facebook:title" content="{{ strtoupper(seo()->facebookTitle) }}" />
|
||||
<meta name="facebook:title" content="{{ strtoupper(seo()->facebookTitle) }}">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue