Skip to content

Commit

Permalink
Adds support for og:locale (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
hofmannsven authored Mar 3, 2023
1 parent 169600d commit 3a17c8e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ url(string $url)
title(string $title)
description(string $description)
image(string $url)
locale(string $locale)

twitterCreator(string $username)
twitterSite(string $username)
Expand Down Expand Up @@ -158,6 +159,16 @@ If you wish to change the URL, call `seo()->url()`:
seo()->url(route('products.show', $this->product));
```

### Locale

To set the `og:locale` property:

```php
seo()->locale('de_DE');
```

Expected format is `language_TERRITORY`.

### Modifiers

You may want to modify certain values before they get inserted into the template. For example, you may want to suffix the meta `<title>` with `| ArchTech` when it has a non-default value.
Expand Down
2 changes: 2 additions & 0 deletions assets/views/components/meta.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

@if(seo('site')) <meta property="og:site_name" content="@seo('site')"> @endif

@if(seo('locale')) <meta property="og:locale" content="@seo('locale')" /> @endif

@if(seo('image')) <meta property="og:image" content="@seo('image')" /> @endif

@if(seo('url'))
Expand Down
3 changes: 2 additions & 1 deletion src/SEOManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @method $this site(string $site = null, ...$args) Set the site name.
* @method $this image(string $url = null, ...$args) Set the cover image.
* @method $this type(string $type = null, ...$args) Set the page type.
* @method $this locale(string $locale = null, ...$args) Set the page locale.
* @method $this twitter(enabled $bool = true, ...$args) Enable the Twitter extension.
* @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author.
* @method $this twitterSite(string $username = null, ...$args) Set the Twitter author.
Expand Down Expand Up @@ -56,7 +57,7 @@ public function all(): array
protected function getKeys(): array
{
return collect([
'site', 'title', 'image', 'description', 'url', 'type',
'site', 'title', 'image', 'description', 'url', 'type', 'locale',
'twitter.creator', 'twitter.site', 'twitter.title', 'twitter.image', 'twitter.description',
])
->merge(array_keys($this->defaults))
Expand Down
11 changes: 11 additions & 0 deletions tests/Pest/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@
->toContain('<meta property="og:type" content="foo" />') // overridden
->not()->toContain('website');
});

test('og:locale is not included by default', function () {
expect(meta())
->not()->toContain('og:locale');
});

test('og:locale can be added to the template', function () {
seo()->locale('de_DE');

expect(meta())->toContain('<meta property="og:locale" content="de_DE" />');
});

0 comments on commit 3a17c8e

Please sign in to comment.