Skip to content

Commit

Permalink
chore: πŸ”€ Merge pull request #8 from elaniin/hotfix/typed-entry-date-type
Browse files Browse the repository at this point in the history
Fix sitemap entry datetime
  • Loading branch information
vlasscontreras authored Jan 27, 2022
2 parents d24b138 + 6fbcd69 commit bb862bd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Sitemap/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Elaniin\Findable\Sitemap;

use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Support\Collection;
use Spatie\Sitemap\Sitemap as SpatieSitemap;
use Spatie\Sitemap\Tags\Url;
Expand Down Expand Up @@ -56,10 +57,25 @@ public static function collection(EntryCollection $entries)
Url::create($entry->url())
->setChangeFrequency('')
->setPriority(0)
->setLastModificationDate(Carbon::createFromTimestamp($entry->lastModified()))
->setLastModificationDate(self::getLastModified($entry))
);
});

return $sitemap;
}

/**
* Get the last modified date of the given entry.
*
* @param Entry $entry
* @return DateTimeInterface
*/
protected static function getLastModified(Entry $entry): DateTimeInterface
{
if (\is_int($entry->lastModified())) {
return Carbon::createFromTimestamp($entry->lastModified());
}

return $entry->lastModified();
}
}

0 comments on commit bb862bd

Please sign in to comment.