published->resolveIndex(); if ($published !== null) { return $this->renderer->xmlResponse($published['content']); } // 2. Live-build fallback when no published sitemap is available. if ((bool) config('sitemaps.delivery.fallback_to_live_build', true)) { $built = $this->build->buildIndex(force: true, persist: false); return $this->renderer->xmlResponse($built['content']); } throw new NotFoundHttpException(); } public function show(string $name): Response|BinaryFileResponse { if ($name === 'sitemap') { return $this->index(); } // 1. Static file. $path = public_path('sitemaps/' . $name . '.xml'); if ((bool) config('sitemaps.pre_generated.enabled', true) && file_exists($path)) { return $this->xmlFileResponse($path); } // 2. Published release. $published = $this->published->resolveNamed($name); if ($published !== null) { return $this->renderer->xmlResponse($published['content']); } if ((bool) config('sitemaps.delivery.fallback_to_live_build', true)) { $built = $this->build->buildNamed($name, force: true, persist: false); if ($built !== null) { return $this->renderer->xmlResponse($built['content']); } } throw new NotFoundHttpException(); } private function xmlFileResponse(string $absolutePath): BinaryFileResponse { return response()->file($absolutePath, [ 'Content-Type' => 'application/xml; charset=UTF-8', 'Cache-Control' => 'public, max-age=' . max(60, (int) config('sitemaps.cache_ttl_seconds', 900)), ]); } }