pedroborges / kirby-meta-tags

⬢ HTML meta tags generator for Kirby. Supports Open Graph and Twitter Cards out of the box.
MIT License
97 stars 11 forks source link

First argument should be a Page #12

Closed HashandSalt closed 5 years ago

HashandSalt commented 5 years ago

I get the following error when you using the the update to composer added today (v2.0).

Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Argument 1 passed to metaTags() must be an instance of Page, instance of Kirby\Cms\Page given, called in /public/site/plugins/meta-tags/index.php on line 8 (View: /public/site/templates/global/metatags.blade.php)

Im using Kirby 3.0.2, and the Blade plugin, but meta tags worked before todays updated that added composer and a few fixes.

pedroborges commented 5 years ago

Thank you for reporting. Try the dev-master version and let me know if it fixes it for you before I tag a new release:

composer require pedroborges/kirby-meta-tags:dev-master@dev

HashandSalt commented 5 years ago

Thanks for trying Pedro. It no longer throws a whoops, but it's only out putting these:

<meta property="og:title" content="Home">
<meta property="og:type" content="website">
<meta property="og:url" content="//localhost:3000">
<link rel="canonical" href="//localhost:3000">

I have an epic setup in the config (excuse the mess, i haven't tidied up yet).....

'pedroborges.metatags.default' => function ($page, $site) {

    $logo = $site->sitelogo()->toFile() ? $site->sitelogo()->toFile()->url() : '';
    $contact = $site->index()->find('hire-us');
    $location = $contact->location()->toLocation();
    $cardsize = $page->twitterposttype();

    if ($cardsize = "tlargesummary") {
        $cardpostsize = "summary_large_image";
    } else {
        $cardpostsize = "summary";
    }

    return [
      'json-ld' => [
          'LocalBusiness' => [
              'name' => $site->title()->value(),
              'url' => $site->url(),
              "email" => $contact->emailaddress()->value(),
              "logo" => $logo,
              "description" => $contact->businessdescription()->value(),
              "sameAs" => [socialprofiles()],
              "telephone" => $contact->telephone()->value(),
              "priceRange" => "$$$ - $$$$$$",
              "openingHours" => [$contact->hours()->value()],
              "address" => [
                "@type" => "PostalAddress",
                "streetAddress" => $contact->streetaddress()->value(),
                "addressLocality" => $contact->addresslocality()->value(),
                "addressRegion" => $contact->addressregion()->value(),
                "postalCode" => $contact->postalcode()->value(),
              ],
              "geo" => [
                "@type" => "GeoCoordinates",
                "latitude" =>  $location->lat(),
                "longitude" => $location->lon(),
              ],
          ]
      ],

      'title' => $page->seotitle().' | '.$site->seotitle(),
      'meta' => [
          'description' => $page->seometa(),
          'keywords' => $page->seokeywords(),
          'robots' => 'index,follow,noodp',
      ],
      'link' => [
          'canonical' => $page->url()
      ],
      'og' => [
          'title' => $page->seotitle().' | '.$site->seotitle(),
          'type' => 'website',
          'site_name' => $site->title(),
          'url' => $page->url(),

          'image' => function ($page) {
              $image = $page->facebookimage()->toFile();
              if ($image) {
                  return $image->focusCrop(1280, 720)->url();
              } else {
                  $image = site()->facebookimage()->toFile();
                  if ($image) {
                      return $image->focusCrop(1280, 720)->url();
                  } else {
                      $image = new Kirby\Image\Image('/assets/images/facebook.jpg');
                      return $image->root();
                  }
              }
          },

          'description' => $page->seometa(),
      ],
      'twitter' => [
          'title' => $page->seotitle().' | '.$site->seotitle(),
          'card' => $cardpostsize,
          'site' => $site->twitterusername(),
          'creator' => $site->twitterhandle(),
          'image' => function ($page) {
            if ($image = $page->twitterimage()->toFile()) {
              return $image->focusCrop(1280, 720)->url();
            } else {
                $image = site()->twitterimage()->toFile();
                if ($image) {
                    return $image->focusCrop(1280, 720)->url();
                } else {
                    $image = new Kirby\Image\Image('/assets/images/twitter.jpg');
                    return $image->root();
                }
            }

          },
          'url' => $page->url(),
          'description' => $page->seometa(),
      ]
    ];
},
pedroborges commented 5 years ago

I changed the options back to the pre-alpha names. So you must add a dash to them:

HashandSalt commented 5 years ago

Ah.. its working now :) Thanks.