statamic / ssg

The official Statamic Static Site Generator
230 stars 23 forks source link

Filter out entries without routing info #30

Closed michaellindahl closed 3 years ago

michaellindahl commented 3 years ago

This fixes #26 and fixes #27 where entries without routes are generated overriding the homepage and excessively generating files. I'm unsure this should also be applied to urls/terms/scopedTerms and if there's a better approach than the one taken here.

michaellindahl commented 3 years ago

So I found a better way of doing this. Previously I was doing:

->filter(function ($entry) {
    return ! is_null($entry->collection()->routes()->get('default'));
})

However, I just realized that Entries are Routable which has a uri() method which returns null when $this->route() doesn't have a value. This seem like the proper solution for Entries. So now I'm doing this:

->reject(function ($entry) {
     return is_null($entry->uri());
})

Terms always have a slug associated with them, which leads me to believe that the urls/terms/scopedTerms do not need this treatment.

jasonvarga commented 3 years ago

Sorry for the delay. Thanks for the PR!