Skip to content

Commit

Permalink
chore: 🔀 merge pull request #7 from elaniin/hotfix/sitemap-json-asser…
Browse files Browse the repository at this point in the history
…tion

Fix fatal error in sitemaps
  • Loading branch information
vlasscontreras authored Jan 27, 2022
2 parents 8a55960 + 9dbba9e commit d24b138
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/Data/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static function public(string $collectionHandle, Site $site)
return EntryFacade::query()
->where('collection', $collectionHandle)
->where('site', $site)
->whereJsonDoesntContain('data', ['noindex_page' => true])
->get();
}
}
26 changes: 16 additions & 10 deletions src/Sitemap/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Elaniin\Findable\Sitemap;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Spatie\Sitemap\Sitemap as SpatieSitemap;
use Spatie\Sitemap\Tags\Url;
use Illuminate\Support\Collection;
use Statamic\Contracts\Entries\Entry;
use Statamic\Entries\EntryCollection;
use Statamic\Facades\Site;

class Sitemap
Expand Down Expand Up @@ -41,18 +43,22 @@ public static function index(Collection $dataTypes)
* @param EntryCollection $entries
* @return SpatieSitemap
*/
public static function collection(\Statamic\Entries\EntryCollection $entries)
public static function collection(EntryCollection $entries)
{
$sitemap = SpatieSitemap::create();

$entries->each(function ($entry) use ($sitemap) {
$sitemap->add(
Url::create($entry->url())
->setChangeFrequency('')
->setPriority(0)
->setLastModificationDate(Carbon::createFromTimestamp($entry->lastModified()))
);
});
$entries
->filter(function (Entry $entry) {
return $entry->get('noindex_page') !== true;
})
->each(function (Entry $entry) use ($sitemap) {
$sitemap->add(
Url::create($entry->url())
->setChangeFrequency('')
->setPriority(0)
->setLastModificationDate(Carbon::createFromTimestamp($entry->lastModified()))
);
});

return $sitemap;
}
Expand Down

0 comments on commit d24b138

Please sign in to comment.