Skip to content

Commit

Permalink
Fix: Sitemap headless mode (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
martink635 authored Apr 5, 2024
1 parent d0e0abc commit 8f5f9ec
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Http/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __invoke()
return self::shouldBeIndexed($entry);
})
->map(function (Entry $entry) {
return $this->sitemapEntry($entry);
return self::sitemapEntry($entry);
});

return view('seotamic::sitemap', [
Expand Down Expand Up @@ -66,7 +66,7 @@ private static function sitemapEntry(Entry $entry)
'seotamic_sitemap_entry' . $entry->id(),
function () use ($entry) {
return [
'loc' => $entry->absoluteUrl(),
'loc' => self::entryAbsoluteUrl($entry),
'lastmod' => $entry->lastModified()->toAtomString(),
'alternates' => $entry->sites()
->map(fn ($site) => $entry->in($site))
Expand All @@ -76,11 +76,21 @@ function () use ($entry) {
->map(function (Entry $entry) {
return array(
'lang' => $entry->locale,
'href' => $entry->absoluteUrl()
'href' => self::entryAbsoluteUrl($entry)
);
})
];
}
);
}

private static function entryAbsoluteUrl(Entry $entry)
{
// if seotamic headless mode is set, use that domain, otherwise use the entry absoluteUrl
if (config('seotamic.headless_mode')) {
return config('seotamic.headless_mode') . $entry->uri();
}

return $entry->absoluteUrl();
}
}

0 comments on commit 8f5f9ec

Please sign in to comment.