-
-
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.
Create a helper for fluent metadata configuration
- Loading branch information
1 parent
10ee751
commit 9d1134b
Showing
3 changed files
with
56 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework; | ||
|
||
class Meta | ||
{ | ||
public static function name(string $name, string $content, bool $ifConditionIsMet = true): ?string | ||
{ | ||
if ($ifConditionIsMet) { | ||
return '<meta name="' . e($name) . '" content="' . e($content) . '">'; | ||
} | ||
return null; | ||
} | ||
|
||
public static function property(string $property, string $content, bool $ifConditionIsMet = true): ?string | ||
{ | ||
if ($ifConditionIsMet) { | ||
$property = static::formatOpenGraphProperty($property); | ||
return '<meta property="' . e($property) . '" content="' . e($content) . '">'; | ||
} | ||
return null; | ||
} | ||
|
||
public static function render(array $overridesGlobalMeta = []): string | ||
{ | ||
return implode("\n", | ||
array_merge( | ||
static::getGlobalMeta(), | ||
$overridesGlobalMeta | ||
) | ||
); | ||
} | ||
|
||
public static function getGlobalMeta(): array | ||
{ | ||
return config('hyde.meta', []); | ||
} | ||
|
||
protected static function formatOpenGraphProperty(string $property): string | ||
{ | ||
return str_starts_with('og:', $property) ? $property : 'og:' . $property; | ||
} | ||
} |