aerni / statamic-advanced-seo

Comprehensive SEO addon for Statamic with flexibility in mind
https://statamic.com/addons/aerni/advanced-seo
10 stars 5 forks source link

Statamic 4 + SSG won't Generate #74

Closed mc4rdle closed 1 year ago

mc4rdle commented 1 year ago

When I run php please ssg:generate I get this error:

Gathering content to be generated...

   Error

  Call to a member function url() on null

  at vendor/statamic/ssg/src/Request.php:51
     47▕     }
     48▕
     49▕     public function getPathInfo(): string
     50▕     {
  ➜  51▕         return $this->page->url();
     52▕     }
     53▕
     54▕     public function path()
     55▕     {

      +34 vendor frames

  35  [internal]:0
      Illuminate\Support\Collection::Illuminate\Support\Traits\{closure}(Object(Statamic\Entries\Entry))
      +21 vendor frames

  57  please:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

As soon as I uninstall it, it generates fine.

My project: Environment Application Name: Keepme Laravel Version: 10.12.0 PHP Version: 8.1.17 Composer Version: 2.5.5 Environment: local Debug Mode: ENABLED URL: keepme.test Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Statamic Addons: 3 Antlers: runtime Stache Watcher: Enabled Static Caching: Disabled Version: 4.3.0 PRO

Statamic Addons aerni/advanced-seo: 2.1.1 statamic/ssg: 2.0.0 stefangalescu/statamic-heroicons: 2.1

mc4rdle commented 1 year ago

I've tried clearing cache and stache but still it persists.

aerni commented 1 year ago

I'm going to need more information to work with. What's causing the error? I just tried to reproduce it on a fresh installation with aerni/advanced-seo and statamic/ssg. I can run ssg:generate without an error.

Please create a fresh repo that reproduces the error so I can take a look at it.

mc4rdle commented 1 year ago

Yea, the logs don't seem to give any clues. I tried to remove everything one by one until it worked. It turns out two collections were causing it (Blog and Webinars), and they both had two things in common:

  1. they were sorted by date
  2. they had a taxonomy linked to the collection

Deleting every entry in both collections stopped the error. Removing the Taxonomy or disabling Enable Publish Dates from the collection alone doesn't stop it, but removing/disabling both on the collection at the same time does, which is strange.

Log File: log.txt

mc4rdle commented 1 year ago

I was able to replicate it on a new site.

  1. Created a fresh new blank statamic site
  2. Install SSG package
  3. Create a collection and give them a URL eg blog/{slug}
  4. Make the collection orderable by date
  5. Attach a taxonomy to the collection
  6. Run php please ssg:generate and it will fail

The collection's yaml file on my new fresh site:

title: Blog
template: blog/show
layout: layout
taxonomies:
  - tags
revisions: false
route: '/blog/{slug}'
date: true
sort_dir: asc
date_behavior:
  past: public
  future: private
preview_targets:
  -
    label: Entry
    url: '{permalink}'
    refresh: true
aerni commented 1 year ago

I tracked this down, and it seems to be an issue with the statamic/ssg package. Advanced SEO depends on the request()->path() to determine if a collection's blueprint should be extended or not. This is where the ssg:generate command fails. I'll open an issue on the repo and see where that goes. I might be able to fix the issue on my end with a nasty workaround. But I rather not.

aerni commented 1 year ago

This is the issue I opened for reference: https://github.com/statamic/ssg/issues/134

mc4rdle commented 1 year ago

Thank you!