web: Strukturierte Daten (JSON-LD) und SEO-Metas fürs öffentliche Frontend
Ergänzt die bislang fehlenden strukturierten Daten auf den Presse-Seiten: - PM-Detailseite: NewsArticle + BreadcrumbList als JSON-LD sowie article:published_time/-section/-tag-Metas und og:image:alt — nur auf der öffentlichen Seite, die noindex-Vorschau bleibt ohne Markup. - Kategorie-Seiten: BreadcrumbList plus hreflang de/en über die lokalisierten Slugs (CategoryPageData liefert dafür neu categoryAlternateSlugs, mit View-Fallback für gecachte Alt-Daten). - Newsroom: Organization-Markup (Logo, Website als sameAs, Boilerplate). - Portal-Homepages: WebSite mit SearchAction (Sitelinks-Searchbox) und Organization. - Layout: og:locale und twitter:image ergänzt; neue Sections meta_extra und structured_data. Neue Komponente x-web.structured-data rendert JSON-LD mit JSON_HEX_TAG, damit "</script>" in Titeln/Teasern das Script-Tag nicht aufbrechen kann. JSON-LD-URLs werden wie der Canonical aus der Portal-Basis gebaut (unabhängig von forceRootUrl), damit Host und Canonical übereinstimmen. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c70e1754e0
commit
379688f4ff
9 changed files with 346 additions and 0 deletions
119
tests/Feature/Web/StructuredDataTest.php
Normal file
119
tests/Feature/Web/StructuredDataTest.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Portal;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\User;
|
||||
use App\Services\Auth\MagicLinkGenerator;
|
||||
use Tests\TestCase;
|
||||
|
||||
function makeStructuredDataRelease(): PressRelease
|
||||
{
|
||||
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
|
||||
$category->translations()->create(['locale' => 'de', 'name' => 'Technologie', 'slug' => 'technologie']);
|
||||
|
||||
$company = Company::factory()->businessportal24()->create(['name' => 'Muster GmbH']);
|
||||
|
||||
return PressRelease::factory()
|
||||
->published()
|
||||
->forPortal(Portal::Businessportal24)
|
||||
->for($category)
|
||||
->for($company)
|
||||
->create([
|
||||
'slug' => 'strukturierte-daten-pm',
|
||||
'title' => 'Strukturierte Daten für Pressemitteilungen',
|
||||
'published_at' => now()->subDay(),
|
||||
]);
|
||||
}
|
||||
|
||||
test('the release detail page emits NewsArticle and BreadcrumbList JSON-LD', function () {
|
||||
/** @var TestCase $this */
|
||||
makeStructuredDataRelease();
|
||||
|
||||
$this->get('https://businessportal24.test/de/press-release/strukturierte-daten-pm')
|
||||
->assertSuccessful()
|
||||
->assertSee('<script type="application/ld+json">', false)
|
||||
->assertSee('"@type":"NewsArticle"', false)
|
||||
->assertSee('"headline":"Strukturierte Daten für Pressemitteilungen"', false)
|
||||
->assertSee('"datePublished"', false)
|
||||
->assertSee('"publisher":{"@type":"Organization","name":"businessportal24"', false)
|
||||
->assertSee('"author":{"@type":"Organization","name":"Muster GmbH"', false)
|
||||
->assertSee('"@type":"BreadcrumbList"', false)
|
||||
->assertSee('"articleSection":"Technologie"', false);
|
||||
});
|
||||
|
||||
test('the release detail page emits article meta tags and og locale', function () {
|
||||
/** @var TestCase $this */
|
||||
makeStructuredDataRelease();
|
||||
|
||||
$this->get('https://businessportal24.test/de/press-release/strukturierte-daten-pm')
|
||||
->assertSuccessful()
|
||||
->assertSee('<meta property="article:published_time" content="', false)
|
||||
->assertSee('<meta property="article:section" content="Technologie">', false)
|
||||
->assertSee('<meta property="og:locale" content="de_DE">', false);
|
||||
});
|
||||
|
||||
test('the private preview emits neither JSON-LD nor article meta tags', function () {
|
||||
/** @var TestCase $this */
|
||||
$owner = User::factory()->create();
|
||||
$release = PressRelease::factory()->forPortal(Portal::Businessportal24)->create([
|
||||
'user_id' => $owner->id,
|
||||
'status' => PressReleaseStatus::Draft->value,
|
||||
]);
|
||||
|
||||
$share = app(MagicLinkGenerator::class)->createPressReleaseShareLink($release, $owner);
|
||||
|
||||
$this->get(route('press-releases.preview', ['token' => $share['plain_token']]))
|
||||
->assertOk()
|
||||
->assertDontSee('application/ld+json', false)
|
||||
->assertDontSee('article:published_time', false);
|
||||
});
|
||||
|
||||
test('a portal homepage emits WebSite JSON-LD with a SearchAction', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->get('https://presseecho.test/de')
|
||||
->assertSuccessful()
|
||||
->assertSee('"@type":"WebSite"', false)
|
||||
->assertSee('"@type":"SearchAction"', false)
|
||||
->assertSee('https://presseecho.test/de/suche?q={search_term_string}', false);
|
||||
});
|
||||
|
||||
test('the newsroom page emits Organization JSON-LD for the company', function () {
|
||||
/** @var TestCase $this */
|
||||
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
|
||||
$category->translations()->create(['locale' => 'de', 'name' => 'Wirtschaft', 'slug' => 'wirtschaft']);
|
||||
|
||||
$company = Company::factory()->businessportal24()->create([
|
||||
'name' => 'Newsroom AG',
|
||||
'website' => 'https://newsroom-ag.example',
|
||||
]);
|
||||
|
||||
PressRelease::factory()
|
||||
->published()
|
||||
->forPortal(Portal::Businessportal24)
|
||||
->for($category)
|
||||
->for($company)
|
||||
->create(['published_at' => now()->subDay()]);
|
||||
|
||||
$this->get('https://businessportal24.test/de/newsroom/'.$company->slug)
|
||||
->assertSuccessful()
|
||||
->assertSee('"@type":"Organization"', false)
|
||||
->assertSee('"name":"Newsroom AG"', false)
|
||||
->assertSee('"sameAs":["https://newsroom-ag.example"]', false);
|
||||
});
|
||||
|
||||
test('the category page emits BreadcrumbList JSON-LD and localized hreflang links', function () {
|
||||
/** @var TestCase $this */
|
||||
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
|
||||
$category->translations()->create(['locale' => 'de', 'name' => 'Technologie', 'slug' => 'technologie']);
|
||||
$category->translations()->create(['locale' => 'en', 'name' => 'Technology', 'slug' => 'technology']);
|
||||
|
||||
$this->get('https://businessportal24.test/de/category/technologie')
|
||||
->assertSuccessful()
|
||||
->assertSee('"@type":"BreadcrumbList"', false)
|
||||
->assertSee('"name":"Technologie"', false)
|
||||
->assertSee('<link rel="alternate" hreflang="de" href="https://businessportal24.test/de/category/technologie">', false)
|
||||
->assertSee('<link rel="alternate" hreflang="en" href="https://businessportal24.test/en/category/technology">', false);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue