From cdb2b01cfef84cc55ef201b85049a7270d543311 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 27 Nov 2023 15:53:08 +0000 Subject: [PATCH] Revert changes not ready for merge GitHub Desktop silently failed to switch branch and I accidentally pushed to master instead of creating a PR. Revert "Extract helper method for resolving sitemap links" This reverts commit 4df9f2f4ae772e83003c7ba6492f1543f98d20b4. Revert "Use relative sitemap links when site URL is for localhost" This reverts commit 84d96f75f6135c29623aac0698eddcb15d3f557f. Revert "Use relative sitemap links when no site URL is set" This reverts commit 6bbfbdc7295dd596540abd036d5b79922c842df5. https://github.com/hydephp/develop/commit/d1fdf50eab59c9702dbe6e7cc70afef15548a465 --- .../XmlGenerators/SitemapGenerator.php | 17 +------------- tests/Feature/Services/SitemapServiceTest.php | 22 ------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/src/Framework/Features/XmlGenerators/SitemapGenerator.php b/src/Framework/Features/XmlGenerators/SitemapGenerator.php index 89e0b2cb..64b5690c 100644 --- a/src/Framework/Features/XmlGenerators/SitemapGenerator.php +++ b/src/Framework/Features/XmlGenerators/SitemapGenerator.php @@ -17,12 +17,10 @@ use Hyde\Foundation\Facades\Routes; use Hyde\Framework\Concerns\TracksExecutionTime; -use function filled; use function filemtime; use function in_array; use function date; use function time; -use function str_starts_with; /** * @see https://www.sitemaps.org/protocol.html @@ -59,7 +57,7 @@ protected function addRoute(Route $route): void { $urlItem = $this->xmlElement->addChild('url'); - $this->addChild($urlItem, 'loc', $this->resolveRouteLink($route)); + $this->addChild($urlItem, 'loc', Hyde::url($route->getOutputPath())); $this->addChild($urlItem, 'lastmod', $this->getLastModDate($route->getSourcePath())); $this->addChild($urlItem, 'changefreq', 'daily'); @@ -105,17 +103,4 @@ protected function getFormattedProcessingTime(): string { return (string) $this->getExecutionTimeInMs(); } - - protected function resolveRouteLink(Route $route): string - { - $baseUrl = Config::getNullableString('hyde.url'); - - $canUseQualifiedUrl = filled($baseUrl) && ! str_starts_with($baseUrl, 'http://localhost'); - - if ($canUseQualifiedUrl) { - return Hyde::url($route->getOutputPath()); - } - - return $route->getLink(); - } } diff --git a/tests/Feature/Services/SitemapServiceTest.php b/tests/Feature/Services/SitemapServiceTest.php index e82342eb..dddc5e42 100644 --- a/tests/Feature/Services/SitemapServiceTest.php +++ b/tests/Feature/Services/SitemapServiceTest.php @@ -158,26 +158,4 @@ public function test_all_route_types_are_discovered() copy(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'), Hyde::path('_pages/index.blade.php')); copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php')); } - - public function testLinksFallbackToRelativeLinksWhenASiteUrlIsNotSet() - { - config(['hyde.url' => null]); - - $service = new SitemapGenerator(); - $service->generate(); - - $this->assertEquals('404.html', $service->getXmlElement()->url[0]->loc); - $this->assertEquals('index.html', $service->getXmlElement()->url[1]->loc); - } - - public function testLinksFallbackToRelativeLinksWhenSiteUrlIsLocalhost() - { - config(['hyde.url' => 'http://localhost']); - - $service = new SitemapGenerator(); - $service->generate(); - - $this->assertEquals('404.html', $service->getXmlElement()->url[0]->loc); - $this->assertEquals('index.html', $service->getXmlElement()->url[1]->loc); - } }