Sitemap pro Host (1h-Cache): Hub listet Landing + Rechts-/Info-Seiten, Spokes zusaetzlich Kategorien (lokalisierte Slugs), oeffentliche Newsrooms und alle im Archiv sichtbaren PMs des Portals (explizit ohne PortalScope, forPortalValues). Suche und Marketing-Platzhalterseiten bleiben draussen. Statische public/robots.txt entfernt (haette die Route verschattet); robots.txt jetzt dynamisch mit Sitemap-Verweis und Disallow fuer /admin, /login, /register, Suche. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
126 lines
4.3 KiB
PHP
126 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\PressRelease;
|
|
use App\Scopes\PortalScope;
|
|
use App\Support\WebPortalContext;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
/**
|
|
* Host-aware XML-Sitemap: Der Hub listet Landing- und Rechts-/Info-Seiten,
|
|
* die Spokes (presseecho, businessportal24) zusätzlich Kategorien, Newsrooms
|
|
* und alle im Archiv sichtbaren Pressemitteilungen ihres Portals. Marketing-
|
|
* Platzhalterseiten (team, presse, karriere, partner) und die Suche bleiben
|
|
* bewusst draußen (R2.4/R3.2). Pro Host eine Stunde gecacht.
|
|
*/
|
|
class SitemapController extends Controller
|
|
{
|
|
/** @var list<string> */
|
|
private const HUB_PAGES = [
|
|
'faq', 'kontakt', 'ueber-uns', 'hilfe', 'api', 'kuendigung',
|
|
'impressum', 'datenschutz', 'agb', 'cookies',
|
|
];
|
|
|
|
/** @var list<string> */
|
|
private const PORTAL_PAGES = [
|
|
'preise', 'veroeffentlichen', 'newsrooms', 'faq', 'kontakt',
|
|
'ueber-uns', 'hilfe', 'api', 'impressum', 'datenschutz', 'agb', 'cookies',
|
|
];
|
|
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
$host = $request->getHost();
|
|
$base = rtrim($request->getSchemeAndHttpHost(), '/');
|
|
$isHub = str_contains($host, 'pressekonto');
|
|
|
|
$xml = Cache::remember('web.sitemap.'.$host, 3600, function () use ($base, $isHub): string {
|
|
$urls = $isHub ? $this->hubUrls($base) : $this->portalUrls($base);
|
|
|
|
return view('web.sitemap', ['urls' => $urls])->render();
|
|
});
|
|
|
|
return response($xml, 200, ['Content-Type' => 'application/xml; charset=UTF-8']);
|
|
}
|
|
|
|
/**
|
|
* @return list<array{loc: string, lastmod: ?string}>
|
|
*/
|
|
private function hubUrls(string $base): array
|
|
{
|
|
$urls = [['loc' => $base.'/', 'lastmod' => null]];
|
|
|
|
foreach (self::HUB_PAGES as $page) {
|
|
$urls[] = ['loc' => $base.'/de/'.$page, 'lastmod' => null];
|
|
}
|
|
|
|
return $urls;
|
|
}
|
|
|
|
/**
|
|
* @return list<array{loc: string, lastmod: ?string}>
|
|
*/
|
|
private function portalUrls(string $base): array
|
|
{
|
|
$context = WebPortalContext::fromRequest();
|
|
|
|
$urls = [['loc' => $base.'/de', 'lastmod' => null]];
|
|
|
|
foreach (self::PORTAL_PAGES as $page) {
|
|
$urls[] = ['loc' => $base.'/de/'.$page, 'lastmod' => null];
|
|
}
|
|
|
|
// Kategorien über die lokalisierten Slugs (CategoryTranslation).
|
|
$categorySlugs = Category::query()
|
|
->where('is_active', true)
|
|
->whereIn('portal', $context->portalValues)
|
|
->with('translations')
|
|
->get()
|
|
->map(fn (Category $category) => $category->translations->firstWhere('locale', 'de')?->slug)
|
|
->filter()
|
|
->unique();
|
|
|
|
foreach ($categorySlugs as $slug) {
|
|
$urls[] = ['loc' => $base.'/de/category/'.$slug, 'lastmod' => null];
|
|
}
|
|
|
|
// Öffentliche Newsrooms: aktive Firmen mit mindestens einer im Archiv
|
|
// sichtbaren PM des Portals (gleiche Regel wie NewsroomsPageData).
|
|
$companies = Company::query()
|
|
->where('is_active', true)
|
|
->whereHas('pressReleases', fn ($query) => $query
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->visibleInArchive()
|
|
->forPortalValues($context->portalValues))
|
|
->get(['slug', 'updated_at']);
|
|
|
|
foreach ($companies as $company) {
|
|
$urls[] = [
|
|
'loc' => $base.'/de/newsroom/'.$company->slug,
|
|
'lastmod' => $company->updated_at?->toAtomString(),
|
|
];
|
|
}
|
|
|
|
// Alle im Archiv sichtbaren Pressemitteilungen des Portals.
|
|
$releases = PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->visibleInArchive()
|
|
->forPortalValues($context->portalValues)
|
|
->orderByDesc('published_at')
|
|
->get(['slug', 'published_at', 'updated_at']);
|
|
|
|
foreach ($releases as $release) {
|
|
$urls[] = [
|
|
'loc' => $base.'/de/press-release/'.$release->slug,
|
|
'lastmod' => ($release->updated_at ?? $release->published_at)?->toAtomString(),
|
|
];
|
|
}
|
|
|
|
return $urls;
|
|
}
|
|
}
|