Closed steffenschmidt closed 2 years ago
Fixed in release 1.2.7
The release 1.2.7 does not fix this issue for me. Anything I have to change beside updating the package?
Maybe a caching issue?
I cleared all caches and started debugging. The interesting part is the following:
I added \Log::debug($content);
in line 30 of SitemapController
:
public function show()
{
$cacheUntil = Carbon::now()->addSeconds(config('pecotamic.sitemap.expire'));
$content = Cache::remember(self::cacheKey(), $cacheUntil, function () {
$view = view('pecotamic/sitemap::sitemap');
return $view->with([
'entries' => self::entriesFor($view),
'xml_header' => '<?xml version="1.0" encoding="UTF-8"?>',
])->render();
});
\Log::debug($content);
return response($content)
->header('Content-Type', 'application/xml')
->header('Expires', $cacheUntil->format('D, d M Y H:i:s T'));
}
Log debug output:
[11:14:54] LOG.debug: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/...
In this output the xml tag is available but with curl http://localhost:8000/sitemap.xml
(also on prod env) the xml tag is missing and also the namespace for urlset:
<urlset><url><loc>http://localhost:8000</loc>...
On my testing device the xml tag is there when I use your antlers template and fetch it with curl
.
I saw that you forked the original repo. Are you sure that the updated version is used? Could the old version be in use for some reason?
The fork was from my pull request I sent you. I checked everything that I use the current release.
I will now create a new project and test your add-on to rule out that it is due to individual settings.
Ok, it's definitely something in my project. The new release works fine in a new project.
I found the error: The html minify plugin kicks the xml header. 🤦♂️
I used an antlers template instead of a blade. This is my code:
This is my expected output for
/sitemap.xml
:This is the output I got for
/sitemap.xml
:The complete xml tag is missing. After switching back to the blade template I found out that there is also output of a xml header.
Any idea how I can fix this?