{{ $defaultHero['title'] ?? 'No lead story yet' }}
{{ $defaultHero['excerpt'] ?? 'We are gathering the biggest stories for this region.' }}
{{ $defaultHero['date'] ?? '' }}@extends('layouts.app') @section('content') @php $regionList = $regions ?? \App\Models\News::REGIONS; $activeRegionKey = (! empty($activeRegion ?? null) && array_key_exists($activeRegion, $regionList)) ? $activeRegion : null; if ($activeRegionKey === null && request()->filled('region')) { $requestedRegion = strtolower((string) request('region')); $activeRegionKey = array_key_exists($requestedRegion, $regionList) ? $requestedRegion : null; } $isRegionView = $activeRegionKey !== null && $activeRegionKey !== 'all'; $articlesCollection = $articles instanceof \Illuminate\Support\Collection ? $articles : collect($articles); $articlesCollection = $articlesCollection->map(function ($article) { $article->region = $article->normalized_region ?? 'all'; if (($article->normalized_secondary_category ?? null) === null && (($article->getAttributes()['region'] ?? null) === 'velemeny') ) { $article->secondary_category = 'velemeny'; } return $article; }); $groupedArticles = $articlesCollection->groupBy(fn ($article) => $article->region ?? 'all'); $mapArticle = function ($article) use ($regionList) { $imagePath = trim($article->display_image_path ?? ''); $imageUrl = $imagePath !== '' ? (\Illuminate\Support\Str::startsWith($imagePath, ['http://', 'https://', '//']) ? $imagePath : asset($imagePath)) : null; $date = $article->published_at ?: $article->created_at; $secondaryCategory = $article->normalized_secondary_category ?? null; $secondaryCategoryLabel = $article->secondary_category_label ?? (\App\Models\News::secondaryCategoryLabels()[$secondaryCategory] ?? null); $regionKey = $article->normalized_region ?? 'all'; $regionLabel = $regionList[$regionKey] ?? ucfirst($regionKey); $taxonomyLabel = $secondaryCategoryLabel !== null ? $regionLabel.' · '.$secondaryCategoryLabel : $regionLabel; return [ 'id' => $article->id, 'title' => $article->title, 'slug' => $article->slug, 'link' => route('news.show', $article->slug), 'excerpt' => $article->excerpt ?: \Illuminate\Support\Str::limit(strip_tags($article->display_body), 160), 'region' => $regionKey, 'regionLabel' => $regionLabel, 'secondaryCategory' => $secondaryCategory, 'secondaryCategoryLabel' => $secondaryCategoryLabel, 'taxonomyLabel' => $taxonomyLabel, 'date' => optional($date)->format('F j, Y'), 'timestamp' => optional($date)->timestamp ?? 0, 'image' => $imageUrl, ]; }; $preparedContent = []; foreach ($regionList as $regionKey => $regionLabel) { $regionArticles = $regionKey === 'all' ? $articlesCollection : ($groupedArticles[$regionKey] ?? collect()); if (! $isRegionView && $regionKey !== 'all') { $regionArticles = $regionArticles->merge($groupedArticles['all'] ?? collect()); } if ($isRegionView && $regionKey !== 'all' && $regionArticles->isEmpty() && isset($groupedArticles['all'])) { $regionArticles = $groupedArticles['all']; } $sortedArticles = $regionArticles->sortByDesc(function ($article) { $date = $article->published_at ?: $article->created_at; return $date ? $date->timestamp : 0; }); $mappedStories = $sortedArticles->map($mapArticle)->values(); $bracketStories = $mappedStories ->filter(fn ($story) => ($story['region'] ?? null) !== 'all') ->take(5) ->values(); $preparedContent[$regionKey] = [ 'heroStory' => $mappedStories->first(), 'secondaryStories' => $mappedStories->slice(1, 4)->values()->all(), 'articles' => $mappedStories->slice(1)->values()->all(), 'bracket' => [ 'region' => $regionKey, 'regionLabel' => $regionLabel, 'items' => $bracketStories->all(), ], ]; } $regionalTaxonomyBrackets = []; $activeRegionLabel = $activeRegionKey ? ($regionList[$activeRegionKey] ?? ucfirst($activeRegionKey)) : null; if ($isRegionView) { $regionOnlyArticles = $groupedArticles[$activeRegionKey] ?? collect(); if ($regionOnlyArticles->isEmpty() && isset($groupedArticles['all'])) { $regionOnlyArticles = $groupedArticles['all']; } $secondaryCategories = \App\Models\News::secondaryCategoryLabels(); foreach ($secondaryCategories as $categoryKey => $categoryLabel) { $categoryArticles = $regionOnlyArticles ->filter(fn ($article) => ($article->secondary_category ?? null) === $categoryKey) ->sortByDesc(function ($article) { $date = $article->published_at ?: $article->created_at; return $date ? $date->timestamp : 0; }); $regionalTaxonomyBrackets[] = [ 'key' => $categoryKey, 'label' => $categoryLabel, 'items' => $categoryArticles->map($mapArticle)->take(5)->values()->all(), ]; } } $weatherFallbackMessage = $weatherFallbackMessage ?? null; $rawWeatherData = is_array($weatherData ?? null) ? $weatherData : []; $normalisedWeatherData = []; foreach ($rawWeatherData as $slug => $forecast) { if (! is_array($forecast)) { continue; } $details = []; if (isset($forecast['details']) && is_array($forecast['details'])) { foreach ($forecast['details'] as $detail) { if (! is_array($detail)) { continue; } $label = $detail['label'] ?? null; $value = $detail['value'] ?? null; if ($label !== null && $value !== null) { $details[] = trim($label . ': ' . $value); continue; } if ($value !== null) { $details[] = $value; continue; } if ($label !== null) { $details[] = $label; } } } $normalisedWeatherData[$slug] = [ 'slug' => $forecast['slug'] ?? $slug, 'label' => $forecast['label'] ?? ($regionList[$slug] ?? ucfirst($slug)), 'summary' => $forecast['summary'] ?? null, 'temperature' => [ 'current' => $forecast['temperature']['current'] ?? null, 'high' => $forecast['temperature']['high'] ?? null, 'low' => $forecast['temperature']['low'] ?? null, ], 'details' => $details, 'observed_at' => $forecast['observed_at'] ?? null, ]; } $defaultWeatherRegion = array_key_first($normalisedWeatherData); $weatherFallback = [ 'label' => 'Weather data unavailable', 'summary' => $weatherFallbackMessage ?? 'Weather information is currently unavailable. Please check back later.', 'temperature' => [ 'current' => null, 'high' => null, 'low' => null, ], 'details' => [], 'observed_at' => null, ]; $standingsPayload = $nb1Standings ?? ['entries' => ['all' => []], 'preferredRegion' => 'all']; $standingsEntries = $standingsPayload['entries'] ?? []; if (! is_array($standingsEntries)) { $standingsEntries = ['all' => []]; } elseif (! \Illuminate\Support\Arr::isAssoc($standingsEntries)) { $standingsEntries = ['all' => $standingsEntries]; } $standingsPayload['entries'] = $standingsEntries; $standingsMetaByRegion = is_array($standingsPayload['meta'] ?? null) ? $standingsPayload['meta'] : []; $preferredStandingsRegion = $standingsPayload['preferredRegion'] ?? 'all'; $preferredStandingsRegion = array_key_exists($preferredStandingsRegion, $standingsEntries) ? $preferredStandingsRegion : (array_key_exists('all', $standingsEntries) ? 'all' : array_key_first($standingsEntries)); $initialStandings = $standingsPayload['initialStandings'] ?? []; $initialStandingsMeta = $standingsPayload['initialMeta'] ?? []; $sportsData = is_array($initialStandings) && $initialStandings !== [] ? $initialStandings : ($standingsEntries[$preferredStandingsRegion] ?? []); $sportsData = is_array($sportsData) ? $sportsData : []; $standingsMetaRaw = is_array($initialStandingsMeta) && $initialStandingsMeta !== [] ? $initialStandingsMeta : ($standingsMetaByRegion[$preferredStandingsRegion] ?? []); $standingsMeta = [ 'isStale' => $standingsMetaRaw['isStale'] ?? empty($sportsData), 'lastUpdated' => $standingsMetaRaw['lastUpdated'] ?? null, ]; $standingsPayload['preferredRegion'] = $preferredStandingsRegion; $standingsPayload['meta'] = $standingsMetaByRegion; $standingsCaption = null; $standingsMetaMessage = null; if (! empty($standingsMeta['lastUpdated'])) { try { $standingsCaption = 'Last updated ' . \Illuminate\Support\Carbon::parse($standingsMeta['lastUpdated']) ->timezone(config('app.timezone')) ->format('M j, Y H:i'); } catch (\Throwable $exception) { $standingsCaption = 'Last updated ' . $standingsMeta['lastUpdated']; } } if (! empty($standingsMeta['isStale'])) { $standingsMetaMessage = 'Data may be delayed.'; } $standingsEmptyMessage = $standingsMeta['isStale'] ? 'Standings unavailable right now. Try refreshing the page shortly.' : 'No standings data available yet.'; @endphp @php $defaultRegionKey = $isRegionView && $activeRegionKey !== null ? $activeRegionKey : (array_key_exists('all', $preparedContent) ? 'all' : array_key_first($preparedContent)); $defaultRegionContent = $defaultRegionKey !== null ? ($preparedContent[$defaultRegionKey] ?? []) : []; $defaultHero = $defaultRegionContent['heroStory'] ?? null; $defaultSecondary = $defaultRegionContent['secondaryStories'] ?? []; $newsPageState = [ 'regions' => $preparedContent, 'regionLabels' => $regionList, 'activeRegion' => $defaultRegionKey, 'weather' => [ 'regions' => $normalisedWeatherData, 'default' => $defaultWeatherRegion, 'fallback' => $weatherFallback, ], 'standings' => $standingsPayload, ]; @endphp
{{ $defaultHero['excerpt'] ?? 'We are gathering the biggest stories for this region.' }}
{{ $defaultHero['date'] ?? '' }}Additional headlines will appear here when they are available.
Friss hírek ebből a kategóriából
We are gathering the latest updates for you. Please select another region or check back soon.