From 16ac328ba4f5dd1e75ec636534330eed53a2e526 Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Wed, 1 Nov 2023 11:56:51 +0100 Subject: [PATCH] register routes explicitly per site (#35) --- routes/web.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/routes/web.php b/routes/web.php index 28ddf48..37c7cb0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,21 +5,28 @@ use Statamic\Facades\Site; use Statamic\Facades\URL; +$useSocialImageGeneration = (bool)GlobalSet::findByHandle('seo')?->inDefaultSite()?->get('use_social_image_generation'); + // The Sitemap Index route for listing sitemaps of all (multi)sites. Route::statamic('/sitemaps.xml', 'statamic-peak-seo::sitemap/sitemaps', [ 'layout' => null, 'content_type' => 'application/xml' ]); -// The Default Site Sitemap route. -Route::statamic(URL::makeRelative(Site::current()->url()).'/sitemap.xml', 'statamic-peak-seo::sitemap/sitemap', [ - 'layout' => null, - 'content_type' => 'application/xml' -]); +// Register routes for each site. +Site::all()->each(function (\Statamic\Sites\Site $site) use ($useSocialImageGeneration) { + $relativeSiteUrl = URL::makeRelative($site->url()); -// The Social Image route to generate social images. -if (GlobalSet::findByHandle('seo')?->inDefaultSite()?->get('use_social_image_generation')) { - Route::statamic(URL::makeRelative(Site::current()->url())."/social-images/{id}", 'statamic-peak-seo::social_images', [ + // The Sitemap route. + Route::statamic(URL::tidy($relativeSiteUrl . '/sitemap.xml'), 'statamic-peak-seo::sitemap/sitemap', [ 'layout' => null, + 'content_type' => 'application/xml' ]); -} + + // The Social Image route to generate social images. + if ($useSocialImageGeneration) { + Route::statamic(URL::tidy($relativeSiteUrl . '/social-images/{id}'), 'statamic-peak-seo::social_images', [ + 'layout' => null, + ]); + } +});