This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General improvements
- Loading branch information
Showing
13 changed files
with
169 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ host = cubexbase.local-host.xyz | |
[dispatch] | ||
opt-sourcemap = false | ||
opt-webp = false | ||
|
||
[site] | ||
title = My Cubex Project |
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,97 @@ | ||
<?php | ||
|
||
namespace CubexBase\Application\Context\Providers; | ||
|
||
use Packaged\Context\Context; | ||
use Packaged\Glimpse\Core\CustomHtmlTag; | ||
|
||
/** | ||
* @method static SeoProvider instance(Context $context) | ||
*/ | ||
class SeoProvider extends AbstractProvider | ||
{ | ||
protected array $tags = []; | ||
protected array $twitterTags = []; | ||
protected array $openGraphTags = []; | ||
|
||
protected string $title = ''; | ||
|
||
public function setTitle(string $title): static | ||
{ | ||
$this->title = $title; | ||
return $this; | ||
} | ||
|
||
public function meta(string $name, string $value) | ||
{ | ||
$this->_push('meta', ['name' => $name, 'content' => $value]); | ||
return $this; | ||
} | ||
|
||
public function og(string $name, string $value) | ||
{ | ||
$this->openGraphTags[] = [ | ||
'meta', | ||
[ | ||
'property' => 'og:' . $name, | ||
'content' => $value, | ||
], | ||
]; | ||
return $this; | ||
} | ||
|
||
public function twitter(string $name, string $value) | ||
{ | ||
$this->twitterTags[] = [ | ||
'meta', | ||
[ | ||
'property' => 'twitter:' . $name, | ||
'content' => $value, | ||
], | ||
]; | ||
return $this; | ||
} | ||
|
||
protected function _push(string $name, array $attrs) | ||
{ | ||
foreach($attrs as $k => $v) | ||
{ | ||
$attrs[$k] = $v; | ||
} | ||
|
||
$this->tags[] = [$name, $attrs]; | ||
return $this; | ||
} | ||
|
||
protected function _build(array $tags) | ||
{ | ||
$out = ''; | ||
foreach($tags as $tag) | ||
{ | ||
$attrs = []; | ||
foreach($tag[1] as $k => $v) | ||
{ | ||
$attrs[$k] = $v; | ||
} | ||
$out .= CustomHtmlTag::build($tag['0'], $attrs, ''); | ||
} | ||
|
||
return $out; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
// Default Site Title | ||
if(empty($this->title)) | ||
{ | ||
$config = $this->getContext()->config()->getSection('site'); | ||
$this->title = $config->getItem('title', 'Default Site Title'); | ||
$this->og('title', $this->title); | ||
} | ||
|
||
$title = CustomHtmlTag::build('title', [], $this->title); | ||
return $title . $this->_build($this->tags) . | ||
$this->_build($this->twitterTags) . | ||
$this->_build($this->openGraphTags); | ||
} | ||
} |
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
Oops, something went wrong.