Skip to content

Commit

Permalink
register routes explicitly per site (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcorieser authored Nov 1, 2023
1 parent c29efae commit 16ac328
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
});

0 comments on commit 16ac328

Please sign in to comment.