Files

25 lines
747 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Models\Site;
use Illuminate\Http\Response;
class SitemapController extends Controller
{
/**
* Lists every static page plus one URL per indexed site. Not paginated/sharded —
* fine at current scale, but a single sitemap is only valid up to 50,000 URLs
* (the sitemap protocol's hard limit), so this will need a sitemap index +
* multiple child sitemaps if the site count ever approaches that.
*/
public function __invoke(): Response
{
$sites = Site::select('id', 'updated_at')->orderBy('id')->get();
$xml = view('sitemap', ['sites' => $sites])->render();
return response($xml, 200)->header('Content-Type', 'application/xml');
}
}