Skip to content

Commit

Permalink
Revert changes not ready for merge
Browse files Browse the repository at this point in the history
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. hydephp/develop@d1fdf50
  • Loading branch information
github-actions committed Nov 27, 2023
1 parent e785f00 commit cdb2b01
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
17 changes: 1 addition & 16 deletions src/Framework/Features/XmlGenerators/SitemapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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();
}
}
22 changes: 0 additions & 22 deletions tests/Feature/Services/SitemapServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cdb2b01

Please sign in to comment.