Skip to content

Commit

Permalink
Merge branch 'master' into custom_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Brk authored Jun 16, 2023
2 parents 16b998d + 99744ea commit 61bf190
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 24 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,27 @@ class CommomController extends Controller
</html>
```

#### Using Macro
Using the same code in multiple places can be tedious, which is why this package includes a Macroable trait. This trait allows additional functionality to be added to a class that was not defined in the class definition, using a simple trait.

For example, imagine that you need to add meta titles and descriptions for your pages. You can add your Macroable functions in the AppServiceProvider or create a dedicated file for this purpose, and define your function as shown in the code snippet:
```php
SEOTools::macro('webPage', function (string $title, string $description) {
SEOMeta::setTitle($title);
SEOMeta::setDescription($description);
SEOMeta::setCanonical('http://current.url.com');
OpenGraph::setDescription($description);
OpenGraph::setTitle($title);
OpenGraph::setUrl('http://current.url.com');
OpenGraph::addProperty('type', 'webpage');
});
```

In your controller, you can use the following code to utilize the function:
```php
SEOTools::webPage('Page title', 'Page description');
```

#### API (SEOMeta)

```php
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
},
"require-dev": {
"orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0"
"phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/SEOTools/Contracts/MetaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function removeMeta($key);
* Add a custom meta tag.
*
* @param string|array $meta
* @param string $value
* @param string|null $value
* @param string $name
*
* @return static
Expand Down
4 changes: 2 additions & 2 deletions src/SEOTools/Contracts/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function setBook($attributes = []);
/**
* Add Video properties.
*
* @param string $source
* @param string|null $source
* @param array $attributes
*
* @return static
Expand All @@ -269,7 +269,7 @@ public function addVideo($source = null, $attributes = []);
/**
* Add audio properties.
*
* @param string $source
* @param string|null $source
* @param array $attributes
*
* @return static
Expand Down
8 changes: 4 additions & 4 deletions src/SEOTools/Facades/JsonLd.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* @see \Artesaos\SEOTools\Contracts\JsonLd
* @method static string generate(bool $minify = false)
* @method static bool isEmpty()
* @method static \Artesaos\SEOTools\Contracts\JsonLd addValue(string $key, array|string $value)
* @method static \Artesaos\SEOTools\Contracts\JsonLd addValue(string $key, string|array $value)
* @method static \Artesaos\SEOTools\Contracts\JsonLd addValues(array $values)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setType(string $type)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setTitle(string $title)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setSite(string $site)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setDescription(string $description)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setUrl(string $url)
* @method static \Artesaos\SEOTools\Contracts\JsonLd addImage(array|string $image)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setImages(array $images)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setUrl(string|null|bool $url)
* @method static \Artesaos\SEOTools\Contracts\JsonLd addImage(string|array $image)
* @method static \Artesaos\SEOTools\Contracts\JsonLd setImages(string|array $images)
*/
class JsonLd extends Facade
{
Expand Down
6 changes: 3 additions & 3 deletions src/SEOTools/Facades/JsonLdMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti newJsonLd()
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti isEmpty()
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti select(int $index)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValue(string $key, array|string $value)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValue(string $key, string|array $value)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValues(array $values)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setType(string $type)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setTitle(string $title)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setSite(string $site)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setDescription(string $description)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setUrl(string $url)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setUrl(string|null|bool $url)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addImage(array|string $image)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setImages(array $images)
* @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setImages(string|array $images)
*/
class JsonLdMulti extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/SEOTools/Facades/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @see \Artesaos\SEOTools\Contracts\OpenGraph
*
* @method static string generate(bool $minify = false)
* @method static \Artesaos\SEOTools\Contracts\OpenGraph addProperty(string $key, array|string $value)
* @method static \Artesaos\SEOTools\Contracts\OpenGraph addProperty(string $key, string|array $value)
* @method static \Artesaos\SEOTools\Contracts\OpenGraph removeProperty(string $key)
* @method static \Artesaos\SEOTools\Contracts\OpenGraph addImage(string $url, array $attributes = [])
* @method static \Artesaos\SEOTools\Contracts\OpenGraph addImages(array $urls)
Expand Down
6 changes: 3 additions & 3 deletions src/SEOTools/Facades/SEOMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @method static \Artesaos\SEOTools\Contracts\MetaTags setTitleDefault(string $default)
* @method static \Artesaos\SEOTools\Contracts\MetaTags setTitleSeparator(string $separator)
* @method static \Artesaos\SEOTools\Contracts\MetaTags setDescription(string $description)
* @method static \Artesaos\SEOTools\Contracts\MetaTags setKeywords(array|string $keywords)
* @method static \Artesaos\SEOTools\Contracts\MetaTags addKeyword(string $keyword)
* @method static \Artesaos\SEOTools\Contracts\MetaTags setKeywords(string|array $keywords)
* @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(array|string $meta, string|null $value = null, string $name = 'name')
* @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)
Expand Down
2 changes: 1 addition & 1 deletion src/SEOTools/Facades/SEOTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @method static \Artesaos\SEOTools\Contracts\SEOTools setTitle(string $title, bool $appendDefault = true)
* @method static \Artesaos\SEOTools\Contracts\SEOTools setDescription(string $description)
* @method static \Artesaos\SEOTools\Contracts\SEOTools setCanonical(string $url)
* @method static \Artesaos\SEOTools\Contracts\SEOTools addImages(array $urls)
* @method static \Artesaos\SEOTools\Contracts\SEOTools addImages(array|string $urls)
* @method static string getTitle(bool $session = false)
*/
class SEOTools extends Facade
Expand Down
5 changes: 3 additions & 2 deletions src/SEOTools/Facades/TwitterCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* @see \Artesaos\SEOTools\Contracts\TwitterCards
*
* @method static string generate(bool $minify = false)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards addValue(string $key, array|string $value)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards addValue(string $key, string|array $value)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setType(string $type)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setTitle(string $title)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setSite(string $site)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setDescription(string $description)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setUrl(string $url)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards addImage(string|array $image)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setImages(array $images)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setImages(string|array $images)
* @method static \Artesaos\SEOTools\Contracts\TwitterCards setImage(string|array $images)
*/
class TwitterCard extends Facade
{
Expand Down
45 changes: 39 additions & 6 deletions src/SEOTools/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ public function setPlace($attributes = [])

/**
* Set product properties.
* Reference: https://developers.facebook.com/docs/marketing-api/catalog/reference/#example-feeds
*
* @param array $attributes opengraph product attributes
*
Expand All @@ -652,25 +653,57 @@ public function setPlace($attributes = [])
public function setProduct($attributes = [])
{
$validkeys = [
// Required
'brand',
'availability',
'condition',

// Conditionally required
'locale',
'plural_title',

// Conditionally required: https://developers.facebook.com/docs/payments/product/
'price:amount', // Required if Static Pricing & not Dynamic Pricing
'price:currency', // Required if Static Pricing & not Dynamic Pricing

// Optional
'catalog_id',
'item_group_id',
'category',
'gender',
'gtin',
'isbn',
'mfr_part_no',

'sale_price:amount',
'sale_price:currency',
'sale_price_dates:start',
'sale_price_dates:end',


// Optional - extra
'custom_label_0',
'custom_label_1',
'custom_label_2',
'custom_label_3',
'custom_label_4',


// Deprecated
'original_price:amount',
'original_price:currency',
'pretax_price:amount',
'pretax_price:currency',
'price:amount',
'price:currency',
'shipping_cost:amount',
'shipping_cost:currency',
'weight:value',
'weight:units',
'shipping_weight:value',
'shipping_weight:units',
'sale_price:amount',
'sale_price:currency',
'sale_price_dates:start',
'sale_price_dates:end'
];

$this->setProperties('product', 'productProperties', $attributes, $validkeys);

return $this;
}

Expand Down
3 changes: 3 additions & 0 deletions src/SEOTools/SEOTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Artesaos\SEOTools;

use Artesaos\SEOTools\Contracts\SEOTools as SEOContract;
use Illuminate\Support\Traits\Macroable;

/**
* SEOTools provides implementation for `SEOTools` contract.
Expand All @@ -11,6 +12,8 @@
*/
class SEOTools implements SEOContract
{
use Macroable;

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 61bf190

Please sign in to comment.