From f91c6c7f74e1c8a8226e1033075c1044d8968377 Mon Sep 17 00:00:00 2001 From: Yaniv Harush Date: Mon, 13 Mar 2023 23:28:41 +0200 Subject: [PATCH 1/4] added custom meta tags and preload links tags --- src/SEOTools/Contracts/MetaTags.php | 19 ++++++++ src/SEOTools/Facades/SEOMeta.php | 2 + src/SEOTools/SEOMeta.php | 74 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/src/SEOTools/Contracts/MetaTags.php b/src/SEOTools/Contracts/MetaTags.php index 0785603..ab485f4 100644 --- a/src/SEOTools/Contracts/MetaTags.php +++ b/src/SEOTools/Contracts/MetaTags.php @@ -141,6 +141,25 @@ public function removeMeta($key); */ public function addMeta($meta, $value = null, $name = 'name'); + /** + * Add a preload link meta tag. + * + * @param string $href + * @param string $as + * + * @return static + */ + public function addPreload($href, $as); + + /** + * Add a custom meta tag. + * + * @param string|array $meta + * + * @return static + */ + public function addCustom($meta); + /** * Sets the canonical URL. * diff --git a/src/SEOTools/Facades/SEOMeta.php b/src/SEOTools/Facades/SEOMeta.php index 051be56..53b105c 100644 --- a/src/SEOTools/Facades/SEOMeta.php +++ b/src/SEOTools/Facades/SEOMeta.php @@ -18,6 +18,8 @@ * @method static \Artesaos\SEOTools\Contracts\MetaTags addKeyword(string $keyword) * @method static \Artesaos\SEOTools\Contracts\MetaTags removeMeta(string $key) * @method static \Artesaos\SEOTools\Contracts\MetaTags addMeta(array|string $meta, string|null $value = null, string $name = 'name') + * @method static \Artesaos\SEOTools\Contracts\MetaTags addPreload(string $href, string $as) + * @method static \Artesaos\SEOTools\Contracts\MetaTags addCustom(array|string $meta) * @method static \Artesaos\SEOTools\Contracts\MetaTags setCanonical(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setPrev(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setNext(string $url) diff --git a/src/SEOTools/SEOMeta.php b/src/SEOTools/SEOMeta.php index f73b0bf..b469ba8 100644 --- a/src/SEOTools/SEOMeta.php +++ b/src/SEOTools/SEOMeta.php @@ -62,6 +62,20 @@ class SEOMeta implements MetaTagsContract */ protected $metatags = []; + /** + * The preload links meta. + * + * @var string + */ + protected $preloads = []; + + /** + * The custom meta tags. + * + * @var string + */ + protected $custom = []; + /** * The canonical URL. * @@ -142,6 +156,8 @@ public function generate($minify = false) $description = $this->getDescription(); $keywords = $this->getKeywords(); $metatags = $this->getMetatags(); + $preloads = $this->getPreloads(); + $custom = $this->getCustoms(); $canonical = $this->getCanonical(); $amphtml = $this->getAmpHtml(); $prev = $this->getPrev(); @@ -181,6 +197,22 @@ public function generate($minify = false) $html[] = ""; } + foreach ($preloads as $preload) { + $href = $preload[0]; + $as = $preload[1]; + + // if $href is empty jump to next + if (empty($href)) { + continue; + } + + $html[] = ""; + } + + foreach ($custom as $meta) { + $html[] = $meta; + } + if ($canonical) { $html[] = ""; } @@ -323,6 +355,28 @@ public function addMeta($meta, $value = null, $name = 'name') return $this; } + /** + * {@inheritdoc} + */ + public function addPreload($href, $as) + { + + $this->preloads[] = [$href, $as]; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function addCustom($meta) + { + + $this->preloads[] = $meta; + + return $this; + } + /** * {@inheritdoc} */ @@ -453,6 +507,26 @@ public function getMetatags() return $this->metatags; } + /** + * Get preload links. + * + * @return string + */ + public function getPreloads() + { + return $this->preloads; + } + + /** + * Get custom meta. + * + * @return string + */ + public function getCustoms() + { + return $this->custom; + } + /** * {@inheritdoc} */ From 896c27eef152a74bddae7405a860da4775cf97e8 Mon Sep 17 00:00:00 2001 From: Yaniv Harush Date: Mon, 13 Mar 2023 23:34:32 +0200 Subject: [PATCH 2/4] wrong array --- src/SEOTools/SEOMeta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SEOTools/SEOMeta.php b/src/SEOTools/SEOMeta.php index b469ba8..41cfb89 100644 --- a/src/SEOTools/SEOMeta.php +++ b/src/SEOTools/SEOMeta.php @@ -372,7 +372,7 @@ public function addPreload($href, $as) public function addCustom($meta) { - $this->preloads[] = $meta; + $this->custom[] = $meta; return $this; } From c485d2805ee2485b6d54ffac4954683abfa320b3 Mon Sep 17 00:00:00 2001 From: Yaniv Harush Date: Thu, 16 Mar 2023 23:12:42 +0200 Subject: [PATCH 3/4] accept only one string --- src/SEOTools/Facades/SEOMeta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SEOTools/Facades/SEOMeta.php b/src/SEOTools/Facades/SEOMeta.php index 53b105c..c9d6da5 100644 --- a/src/SEOTools/Facades/SEOMeta.php +++ b/src/SEOTools/Facades/SEOMeta.php @@ -19,7 +19,7 @@ * @method static \Artesaos\SEOTools\Contracts\MetaTags removeMeta(string $key) * @method static \Artesaos\SEOTools\Contracts\MetaTags addMeta(array|string $meta, string|null $value = null, string $name = 'name') * @method static \Artesaos\SEOTools\Contracts\MetaTags addPreload(string $href, string $as) - * @method static \Artesaos\SEOTools\Contracts\MetaTags addCustom(array|string $meta) + * @method static \Artesaos\SEOTools\Contracts\MetaTags addCustom(string $meta) * @method static \Artesaos\SEOTools\Contracts\MetaTags setCanonical(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setPrev(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setNext(string $url) From 16b998d415e827caeded6504b363924dd613e6c6 Mon Sep 17 00:00:00 2001 From: Yaniv Harush Date: Thu, 16 Mar 2023 23:13:11 +0200 Subject: [PATCH 4/4] removed unnecessary check --- src/SEOTools/SEOMeta.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/SEOTools/SEOMeta.php b/src/SEOTools/SEOMeta.php index 41cfb89..1a2fc18 100644 --- a/src/SEOTools/SEOMeta.php +++ b/src/SEOTools/SEOMeta.php @@ -201,11 +201,6 @@ public function generate($minify = false) $href = $preload[0]; $as = $preload[1]; - // if $href is empty jump to next - if (empty($href)) { - continue; - } - $html[] = ""; }