Skip to content

Commit

Permalink
fix: fix jsonLdSchema again (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Feb 25, 2024
1 parent b4703d6 commit 650890a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
30 changes: 23 additions & 7 deletions app/Http/ViewModels/Names/NameViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,30 @@ public static function popularity(Name $name): array
public static function jsonLdSchema(Name $name): array
{
return [
'@context' => 'http://schema.org/',
'@type' => 'Article',
'mainEntityOfPage' => [
'@type' => 'WebPage',
'@id' => route('name.show', [
'id' => $name->id,
'name' => StringHelper::sanitizeNameForURL($name->name),
]),
],
'author' => [
'@type' => 'Organization',
'name' => config('app.org'),
],
'publisher' => [
'@type' => 'Organization',
'name' => config('app.org'),
'logo' => [
'@type' => 'ImageObject',
'url' => asset('/img/facebook.png'),
],
],
'headline' => 'Tout savoir sur le prénom ' . StringHelper::formatNameFromDB($name->name),
'image' => asset('/img/facebook.png'),
'updated_at' => $name->updated_at->format('Y-m-d'),
'created_at' => $name->updated_at->format('Y-m-d'),
'url' => route('name.show', [
'id' => $name->id,
'name' => StringHelper::sanitizeNameForURL($name->name),
]),
'datePublished' => $name->created_at->format('Y-m-d'),
'dateModified' => $name->updated_at->format('Y-m-d'),
];
}

Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

'name' => env('APP_REALNAME', env('APP_NAME', 'Tous les prénoms')),

'org' => 'touslesprenoms.org',

/*
|--------------------------------------------------------------------------
| Application Environment
Expand Down
25 changes: 1 addition & 24 deletions resources/views/names/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
<x-guest-layout>
<x-slot:jsonLdSchema>
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Article",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ $jsonLdSchema['url'] }}"
},
"author": {
"@type": "Organization",
"name": "touslesprenoms.org"
},
"publisher": {
"@type": "Organization",
"name": "touslesprenoms.org",
"logo": {
"@type": "ImageObject",
"url": "{{ $jsonLdSchema['image'] }}"
}
},
"headline": "{{ $jsonLdSchema['headline'] }}",
"image": {{ $jsonLdSchema['image'] }},
"datePublished": "{{ $jsonLdSchema['created_at'] }}",
"dateModified": "{{ $jsonLdSchema['updated_at'] }}",
}
{!! json_encode($jsonLdSchema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) !!}
</script>
</x-slot>

Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/ViewModels/Names/NameViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,27 @@ public function it_gets_the_data_to_feed_the_json_schema_ld_file(): void

$this->assertEquals(
[
'@context' => 'http://schema.org/',
'@type' => 'Article',
'mainEntityOfPage' => [
'@type' => 'WebPage',
'@id' => env('APP_URL') . '/prenoms/' . $name->id . '/heloise',
],
'author' => [
'@type' => 'Organization',
'name' => 'touslesprenoms.org',
],
'publisher' => [
'@type' => 'Organization',
'name' => 'touslesprenoms.org',
'logo' => [
'@type' => 'ImageObject',
'url' => env('APP_URL') . '/img/facebook.png',
],
],
'headline' => 'Tout savoir sur le prénom Héloïse',
'image' => env('APP_URL') . '/img/facebook.png',
'created_at' => '2018-01-01',
'updated_at' => '2018-01-01',
'url' => env('APP_URL') . '/prenoms/' . $name->id . '/heloise',
'datePublished' => '2018-01-01',
'dateModified' => '2018-01-01',
],
$array
);
Expand Down

0 comments on commit 650890a

Please sign in to comment.