Skip to content

Commit 84d96f7

Browse files
committed
Use relative sitemap links when site URL is for localhost
1 parent 6bbfbdc commit 84d96f7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use function in_array;
2323
use function date;
2424
use function time;
25+
use function str_starts_with;
2526

2627
/**
2728
* @see https://www.sitemaps.org/protocol.html
@@ -109,7 +110,7 @@ protected function resolveRouteLink(Route $route): string
109110
{
110111
$baseUrl = Config::getNullableString('hyde.url');
111112

112-
$canUseQualifiedUrl = filled($baseUrl);
113+
$canUseQualifiedUrl = filled($baseUrl) && ! str_starts_with($baseUrl, 'http://localhost');
113114

114115
if ($canUseQualifiedUrl) {
115116
return Hyde::url($route->getOutputPath());

packages/framework/tests/Feature/Services/SitemapServiceTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,15 @@ public function testLinksFallbackToRelativeLinksWhenASiteUrlIsNotSet()
169169
$this->assertEquals('404.html', $service->getXmlElement()->url[0]->loc);
170170
$this->assertEquals('index.html', $service->getXmlElement()->url[1]->loc);
171171
}
172+
173+
public function testLinksFallbackToRelativeLinksWhenSiteUrlIsLocalhost()
174+
{
175+
config(['hyde.url' => 'http://localhost']);
176+
177+
$service = new SitemapGenerator();
178+
$service->generate();
179+
180+
$this->assertEquals('404.html', $service->getXmlElement()->url[0]->loc);
181+
$this->assertEquals('index.html', $service->getXmlElement()->url[1]->loc);
182+
}
172183
}

0 commit comments

Comments
 (0)