Skip to content

Commit 69b8a0c

Browse files
Fix empty sitemap URLs when site inherits defaults from parent (#572)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 95b70ed commit 69b8a0c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/Sitemap/Sitemap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected function additionalItems(): IlluminateCollection
248248

249249
protected function getSiteDefaults(string $site): array
250250
{
251-
return Blink::once("seo-pro.site-defaults.{$site}", fn () => SiteDefaults::in($site)->all());
251+
return Blink::once("seo-pro.site-defaults.{$site}", fn () => SiteDefaults::in($site)->values()->all());
252252
}
253253

254254
protected function hrefLangs($content): array

tests/Localized/SitemapTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use PHPUnit\Framework\Attributes\DataProvider;
66
use PHPUnit\Framework\Attributes\Test;
7+
use Statamic\Facades\Addon;
8+
use Statamic\Facades\Blink;
79
use Statamic\Facades\URL;
810
use Statamic\SeoPro\SiteDefaults\SiteDefaults;
911

@@ -141,6 +143,46 @@ public function it_uses_localized_site_defaults_in_sitemap_xml($setupTrailingSla
141143
$this->assertCount(15, $this->getPagesFromSitemapXml($content));
142144
}
143145

146+
#[Test]
147+
/**
148+
* https://github.com/statamic/seo-pro/pull/572
149+
*/
150+
public function it_outputs_sitemap_with_loc_when_child_site_inherits_from_parent()
151+
{
152+
Addon::get('statamic/seo-pro')->settings()->set('site_defaults_sites', [
153+
'default' => null,
154+
'french' => null,
155+
'italian' => null,
156+
'british' => 'default',
157+
])->save();
158+
159+
SiteDefaults::in('default')
160+
->set('canonical_url', '@seo:permalink')
161+
->set('change_frequency', 'monthly')
162+
->set('priority', 0.5)
163+
->save();
164+
165+
Blink::forget('seo-pro::site-defaults');
166+
167+
$content = $this
168+
->get('http://cool-runnings.com/sitemap.xml')
169+
->assertOk()
170+
->getContent();
171+
172+
$pages = $this->getPagesFromSitemapXml($content);
173+
174+
foreach ($pages as $page) {
175+
$this->assertNotEmpty($page['loc'], 'All pages should have a non-empty <loc> element');
176+
$this->assertStringStartsWith('http://cool-runnings.com', $page['loc']);
177+
}
178+
179+
$britishLocs = collect($pages)->pluck('loc')->filter(fn ($loc) => str_contains($loc, '/en-gb'));
180+
$this->assertNotEmpty($britishLocs, 'British site entries should be in the sitemap');
181+
foreach ($britishLocs as $loc) {
182+
$this->assertStringStartsWith('http://cool-runnings.com/en-gb', $loc);
183+
}
184+
}
185+
144186
protected function getPagesFromSitemapXml($content)
145187
{
146188
$data = json_decode(json_encode(simplexml_load_string($content)), true);

0 commit comments

Comments
 (0)