Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload links & Custom Tags #300

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/SEOTools/Contracts/MetaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions src/SEOTools/Facades/SEOMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @method static \Artesaos\SEOTools\Contracts\MetaTags addKeyword(string|array $keyword)
* @method static \Artesaos\SEOTools\Contracts\MetaTags removeMeta(string $key)
* @method static \Artesaos\SEOTools\Contracts\MetaTags addMeta(string|array $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(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)
Expand Down
69 changes: 69 additions & 0 deletions src/SEOTools/SEOMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -181,6 +197,17 @@ public function generate($minify = false)
$html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
}

foreach ($preloads as $preload) {
$href = $preload[0];
$as = $preload[1];

$html[] = "<link rel=\"preload\" href=\"{$href}\" as=\"{$as}\" />";
}

foreach ($custom as $meta) {
$html[] = $meta;
}

if ($canonical) {
$html[] = "<link rel=\"canonical\" href=\"{$canonical}\">";
}
Expand Down Expand Up @@ -325,6 +352,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->custom[] = $meta;

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -481,6 +530,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}
*/
Expand Down