diff --git a/composer.json b/composer.json index dc1cb18..56ea389 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,9 @@ "phpstan/phpstan-phpunit": "^1.3" }, "autoload": { + "files": [ + "src/helpers.php" + ], "psr-4": { "Elegantly\\Seo\\": "src/", "Elegantly\\Seo\\Database\\Factories\\": "database/factories/" diff --git a/config/seo.php b/config/seo.php index 5f595ca..328baff 100644 --- a/config/seo.php +++ b/config/seo.php @@ -3,8 +3,12 @@ // config for Elegantly/Seo return [ - 'title' => env('APP_NAME'), + 'title' => env('APP_NAME', 'Laravel'), - 'robots' => null, + 'robots' => 'max-snippet:-1,max-image-preview:large,max-video-preview:-1', + + 'sitemap' => '/sitemap.xml', + + 'image' => null, ]; diff --git a/src/Facades/Seo.php b/src/Facades/Seo.php deleted file mode 100644 index 7d5aeaa..0000000 --- a/src/Facades/Seo.php +++ /dev/null @@ -1,16 +0,0 @@ -title = $title ?? config('seo.title') ?? ''; + $this->canonical = $canonical ?? URL::current(); + } +} diff --git a/src/SeoManager.php b/src/SeoManager.php index 818ba39..074bd6d 100644 --- a/src/SeoManager.php +++ b/src/SeoManager.php @@ -2,11 +2,13 @@ namespace Elegantly\Seo; +use Elegantly\Seo\Contracts\HasSeo; use Elegantly\Seo\Contracts\Taggable; use Elegantly\Seo\OpenGraph\Verticals\Vertical; use Elegantly\Seo\Schemas\Schema; use Elegantly\Seo\Standard\StandardData; use Elegantly\Seo\Twitter\Cards\Card; +use Elegantly\Seo\Unified\SeoUnifiedData; class SeoManager implements Taggable { @@ -21,6 +23,29 @@ public function __construct( public ?SeoTags $customTags = null, ) {} + public function from( + null|SeoData|SeoUnifiedData|SeoManager|HasSeo $value = null + ): SeoManager { + + if ($value instanceof SeoManager) { + return $value; + } + + if ($value instanceof SeoData) { + return $value->toManager(); + } + + if ($value instanceof SeoUnifiedData) { + return $value->toManager(); + } + + if ($value instanceof HasSeo) { + return $this->from($value->getSeoData()); + } + + return $this->from(new SeoData); + } + public function toTags(): SeoTags { $tags = new SeoTags; diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..7958a34 --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,13 @@ +toTags()->toHtml() + )->toBe(implode("\n", [ + '