diff --git a/src/Quintype/Seo/Base.php b/src/Quintype/Seo/Base.php index b482e7c..9bc56cd 100644 --- a/src/Quintype/Seo/Base.php +++ b/src/Quintype/Seo/Base.php @@ -24,7 +24,7 @@ private function getSeoMetadata() { } - protected function getTitle(){ + protected function getPageTitle(){ if(isset($this->seoMetadata['page-title'])){ return $this->seoMetadata['page-title']; } else { @@ -32,6 +32,22 @@ protected function getTitle(){ } } + protected function getTitle(){ + if(isset($this->seoMetadata['title'])){ + return $this->seoMetadata['title']; + } else { + return $this->config['title']; + } + } + + protected function getDescription(){ + if(isset($this->seoMetadata['description'])){ + return $this->seoMetadata['description']; + } else { + return ''; + } + } + protected function getFacebookData($key){ if(isset($this->config['facebook'])){ if(isset($this->config['facebook'][$key])){ diff --git a/src/Quintype/Seo/Home.php b/src/Quintype/Seo/Home.php index 2ca4d44..d772af5 100644 --- a/src/Quintype/Seo/Home.php +++ b/src/Quintype/Seo/Home.php @@ -10,15 +10,15 @@ function tags() { if (sizeof($this->seoMetadata)>0){ return [ - 'title' => trim($this->getTitle()), - 'description' => trim($this->seoMetadata['description']), + 'title' => trim($this->getPageTitle()), + 'description' => trim($this->getDescription()), 'og' => [ - 'title' => trim($this->seoMetadata['title']), - 'description' => trim($this->seoMetadata['description']) + 'title' => trim($this->getTitle()), + 'description' => trim($this->getDescription()) ], 'twitter' => [ - 'title' => trim($this->seoMetadata['title']), - 'description' => trim($this->seoMetadata['description']) + 'title' => trim($this->getTitle()), + 'description' => trim($this->getDescription()) ], 'msvalidate.01' => $this->getBingId(), 'fb' => [ @@ -28,11 +28,11 @@ function tags() { 'alternate' => [ 'href' => '/feed', 'type' => 'application/atom+xml', - 'title' => trim($this->getTitle()) . " ATOM Feed" + 'title' => trim($this->getPageTitle()) . " ATOM Feed" ] ]; } else { - return ['title' => trim($this->getTitle())]; + return ['title' => trim($this->getPageTitle())]; } } diff --git a/src/Quintype/Seo/Section.php b/src/Quintype/Seo/Section.php index d353f7e..0642c1e 100644 --- a/src/Quintype/Seo/Section.php +++ b/src/Quintype/Seo/Section.php @@ -15,23 +15,23 @@ function tags() { if (sizeof($this->seoMetadata)>0){ return [ - 'title' => trim($this->getTitle()), - 'description' => trim($this->seoMetadata['description']), + 'title' => trim($this->getPageTitle()), + 'description' => trim($this->getDescription()), 'og' => [ - 'title' => trim($this->seoMetadata['title']), - 'description' => trim($this->seoMetadata['description']) + 'title' => trim($this->getTitle()), + 'description' => trim($this->getDescription()) ], 'twitter' => [ - 'title' => trim($this->seoMetadata['title']), - 'description' => trim($this->seoMetadata['description']) + 'title' => trim($this->getTitle()), + 'description' => trim($this->getDescription()) ] ]; } else { - return ['title' => trim($this->getTitle())]; + return ['title' => trim($this->getPageTitle())]; } } - protected function getTitle(){ + protected function getPageTitle(){ if(isset($this->seoMetadata['page-title'])){ return $this->seoMetadata['page-title']; } else { diff --git a/src/Quintype/Seo/Story.php b/src/Quintype/Seo/Story.php index 5db429c..8ee39cd 100644 --- a/src/Quintype/Seo/Story.php +++ b/src/Quintype/Seo/Story.php @@ -16,8 +16,8 @@ function tags() { if (sizeof($this->story)>0){ return [ - 'title' => trim($this->getTitle()), - 'description' => trim($this->story['summary']), + 'title' => trim($this->getPageTitle()), + 'description' => trim($this->getDescription()), 'og' => $this->getOgAttributes(), 'twitter' => $this->getTwitterAttributes(), 'msvalidate.01' => $this->getBingId(), @@ -29,22 +29,38 @@ function tags() { 'publisher' => $this->getPublisher() ], 'rel:canonical' => $this->getCanonicalUrl(), - 'al:android:package' => $this->getPublisher('al:android:package'), - 'al:android:app-name' => $this->getPublisher('al:android:app-name'), + 'al:android:package' => $this->getAndroidData('al:android:package'), + 'al:android:app-name' => $this->getAndroidData('al:android:app-name'), 'al:android:url' => "quintypefb://" . $this->config['sketches-host'] . "/". $this->story['slug'] ]; } else { - return ['title' => $this->getTitle()]; + return ['title' => $this->getPageTitle()]; + } + } + + protected function getDescription(){ + if(isset($this->story['summary'])){ + return $this->story['summary']; + } else { + return ''; + } + } + + protected function getTitle(){ + if(isset($this->story['headline'])){ + return $this->story['headline']; + } else { + return $this->config['title']; } } private function getOgAttributes(){ $attributes = [ - 'title' => trim($this->story['headline']), + 'title' => trim($this->getTitle()), 'type' => 'article', 'url' => $this->getCanonicalUrl(), 'site-name' => trim($this->config['title']), - 'description' => trim($this->story['summary']), + 'description' => trim($this->getDescription()), 'image' => $this->getHeroImageUrl() ]; @@ -68,8 +84,8 @@ private function getOgAttributes(){ private function getTwitterAttributes(){ $attributes = [ - 'title' => trim($this->story['headline']), - 'description' => trim($this->story['summary']), + 'title' => trim($this->getTitle()), + 'description' => trim($this->getDescription()), 'card' => 'summary-large-image', 'site' => $this->getTwitterSite(), 'image' => [ @@ -100,7 +116,9 @@ private function getPublisher(){ private function getAndroidData($element){ if(isset($this->config['apps-data'])){ - return $this->config['apps-data'][$element]; + if(isset($this->config['apps-data'][$element])){ + return $this->config['apps-data'][$element]; + } } }