-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from hydephp/fluent-metadata-handler
Unify the $page property and add a fluent metadata helper
- Loading branch information
Showing
16 changed files
with
290 additions
and
67 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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
by author | ||
<address itemprop="author" itemscope itemtype="https://schema.org/Person" aria-label="The post author" style="display: inline;"> | ||
@if($post->author->website) | ||
<a href="{{ $post->author->website }}" rel="author" itemprop="url" aria-label="The author's website"> | ||
@if($page->author->website) | ||
<a href="{{ $page->author->website }}" rel="author" itemprop="url" aria-label="The author's website"> | ||
@endif | ||
<span itemprop="name" aria-label="The author's name" {{ ($post->author->username && ($post->author->username !== $post->author->name)) ? 'title=@'. urlencode($post->author->username) .'' : '' }}>{{ $post->author->name ?? $post->author->username }}</span> | ||
@if($post->author->website) | ||
<span itemprop="name" aria-label="The author's name" {{ ($page->author->username && ($page->author->username !== $page->author->name)) ? 'title=@'. urlencode($page->author->username) .'' : '' }}>{{ $page->author->name ?? $page->author->username }}</span> | ||
@if($page->author->website) | ||
</a> | ||
@endif | ||
</address> |
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 |
---|---|---|
@@ -1 +1 @@ | ||
in the category "{{ $post->category }}" | ||
in the category "{{ $page->category }}" |
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 |
---|---|---|
@@ -1 +1 @@ | ||
Posted <time itemprop="dateCreated datePublished" datetime="{{ $post->date->datetime }}" title="{{ $post->date->sentence }}">{{ $post->date->short }}</time> | ||
Posted <time itemprop="dateCreated datePublished" datetime="{{ $page->date->datetime }}" title="{{ $page->date->sentence }}">{{ $page->date->short }}</time> |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<p itemprop="abstract"> | ||
{{ $post->matter['description'] }} | ||
{{ $page->matter['description'] }} | ||
</p> |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<figure aria-label="Cover image" role="doc-cover" itemprop="image" itemscope itemtype="https://schema.org/ImageObject"> | ||
<img src="{{ $post->image->getSource() }}" alt="{{ $post->image->description ?? '' }}" title="{{ $post->image->title ?? '' }}" itemprop="image" class="mb-0"> | ||
<img src="{{ $page->image->getSource() }}" alt="{{ $page->image->description ?? '' }}" title="{{ $page->image->title ?? '' }}" itemprop="image" class="mb-0"> | ||
<figcaption aria-label="Image caption" itemprop="caption"> | ||
{!! $post->image->getFluentAttribution() !!} | ||
{!! $page->image->getFluentAttribution() !!} | ||
</figcaption> | ||
@foreach ($post->image->getMetadataArray() as $name => $value) | ||
@foreach ($page->image->getMetadataArray() as $name => $value) | ||
<meta itemprop="{{ $name }}" content="{{ $value }}"> | ||
@endforeach | ||
</figure> |
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
{{-- Config Defined Meta Tags --}} | ||
@foreach (config('hyde.meta', []) as $name => $content) | ||
<meta name="{{ $name }}" content="{{ $content }}"> | ||
@endforeach | ||
|
||
@foreach (config('hyde.ogProperties', []) as $property => $content) | ||
<meta property="og:{{ $property }}" content="{{ $content }}"> | ||
@endforeach | ||
{!! Hyde\Framework\Meta::render() !!} | ||
|
||
{{-- Add any extra tags to include in the <head> section --}} | ||
@stack('meta') | ||
|
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,62 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework; | ||
|
||
/** | ||
* Helpers to fluently declare HTML meta tags. | ||
* | ||
* @see \Tests\Feature\MetadataHelperTest | ||
*/ | ||
class Meta | ||
{ | ||
public static function name(string $name, string $content): string | ||
{ | ||
return '<meta name="'.e($name).'" content="'.e($content).'">'; | ||
} | ||
|
||
public static function property(string $property, string $content): string | ||
{ | ||
$property = static::formatOpenGraphProperty($property); | ||
|
||
return '<meta property="'.e($property).'" content="'.e($content).'">'; | ||
} | ||
|
||
public static function render(array $overridesGlobalMeta = []): string | ||
{ | ||
return implode("\n", | ||
static::filterUnique( | ||
array_merge( | ||
static::getGlobalMeta(), | ||
$overridesGlobalMeta | ||
) | ||
) | ||
); | ||
} | ||
|
||
protected static function filterUnique(array $meta): array | ||
{ | ||
$array = []; | ||
$existing = []; | ||
|
||
foreach ($meta as $metaItem) { | ||
$substring = substr($metaItem, 6, strpos($metaItem, ' content="') - 6); | ||
|
||
if (! in_array($substring, $existing)) { | ||
$array[] = $metaItem; | ||
$existing[] = $substring; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
public static function getGlobalMeta(): array | ||
{ | ||
return config('hyde.meta', []); | ||
} | ||
|
||
protected static function formatOpenGraphProperty(string $property): string | ||
{ | ||
return str_starts_with($property, 'og:') ? $property : 'og:'.$property; | ||
} | ||
} |
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.