From 3159cae97285cf6a81baf5138e2fa8e32c966ffa Mon Sep 17 00:00:00 2001 From: Christian Giupponi Date: Wed, 1 Aug 2018 17:52:53 +0200 Subject: [PATCH 1/4] Add canonical url and alternate links for each language available --- .../Http/Controllers/PublicController.php | 41 +++++++++++++++---- Themes/Flatly/views/layouts/master.blade.php | 12 +++--- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Modules/Page/Http/Controllers/PublicController.php b/Modules/Page/Http/Controllers/PublicController.php index 7c23ef337..5d5914782 100644 --- a/Modules/Page/Http/Controllers/PublicController.php +++ b/Modules/Page/Http/Controllers/PublicController.php @@ -19,17 +19,16 @@ class PublicController extends BasePublicController */ private $app; - private $disabledPage = false; - public function __construct(PageRepository $page, Application $app) { parent::__construct(); $this->page = $page; - $this->app = $app; + $this->app = $app; } /** * @param $slug + * * @return \Illuminate\View\View */ public function uri($slug) @@ -46,7 +45,9 @@ public function uri($slug) $template = $this->getTemplateForPage($page); - return view($template, compact('page')); + $alternate = $this->getAlternateMetaData($page); + + return view($template, compact('page', 'alternate')); } /** @@ -60,13 +61,17 @@ public function homepage() $template = $this->getTemplateForPage($page); - return view($template, compact('page')); + $alternate = $this->getAlternateMetaData($page); + + return view($template, compact('page', 'alternate')); } /** * Find a page for the given slug. * The slug can be a 'composed' slug via the Menu + * * @param string $slug + * * @return Page */ private function findPageForSlug($slug) @@ -83,7 +88,9 @@ private function findPageForSlug($slug) /** * Return the template for the given page * or the default template if none found + * * @param $page + * * @return string */ private function getTemplateForPage($page) @@ -92,13 +99,33 @@ private function getTemplateForPage($page) } /** - * Throw a 404 error page if the given page is not found or draft + * Throw a 404 error page if the given page is not found + * * @param $page */ private function throw404IfNotFound($page) { - if (null === $page || $page->status === $this->disabledPage) { + if (is_null($page)) { $this->app->abort('404'); } } + + /** + * Create a key=>value array for alternate links + * + * @param $page + * + * @return array + */ + private function getAlternateMetaData($page) + { + $translations = $page->getTranslationsArray(); + + $alternate = []; + foreach ($translations as $locale => $data) { + $alternate[$locale] = $data['slug']; + } + + return $alternate; + } } diff --git a/Themes/Flatly/views/layouts/master.blade.php b/Themes/Flatly/views/layouts/master.blade.php index 844544e6e..ab5030f9d 100644 --- a/Themes/Flatly/views/layouts/master.blade.php +++ b/Themes/Flatly/views/layouts/master.blade.php @@ -3,12 +3,14 @@ @section('meta') - + @show - - @section('title')@setting('core::site-name')@show - + @section('title')@setting('core::site-name')@show + @foreach($alternate as $alternateLocale=>$alternateSlug) + + @endforeach + {!! Theme::style('css/main.css') !!} @@ -30,7 +32,7 @@ @yield('scripts') - {!! Setting::get('core::analytics-script') !!} +{!! Setting::get('core::analytics-script') !!} @stack('js-stack') From e46f790515020c27971cd6dee6e0f87188e0d72a Mon Sep 17 00:00:00 2001 From: Christian Giupponi Date: Wed, 1 Aug 2018 17:55:53 +0200 Subject: [PATCH 2/4] Revert "Add canonical url and alternate links for each language available" This reverts commit 3159cae97285cf6a81baf5138e2fa8e32c966ffa. --- .../Http/Controllers/PublicController.php | 41 ++++--------------- Themes/Flatly/views/layouts/master.blade.php | 12 +++--- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/Modules/Page/Http/Controllers/PublicController.php b/Modules/Page/Http/Controllers/PublicController.php index 5d5914782..7c23ef337 100644 --- a/Modules/Page/Http/Controllers/PublicController.php +++ b/Modules/Page/Http/Controllers/PublicController.php @@ -19,16 +19,17 @@ class PublicController extends BasePublicController */ private $app; + private $disabledPage = false; + public function __construct(PageRepository $page, Application $app) { parent::__construct(); $this->page = $page; - $this->app = $app; + $this->app = $app; } /** * @param $slug - * * @return \Illuminate\View\View */ public function uri($slug) @@ -45,9 +46,7 @@ public function uri($slug) $template = $this->getTemplateForPage($page); - $alternate = $this->getAlternateMetaData($page); - - return view($template, compact('page', 'alternate')); + return view($template, compact('page')); } /** @@ -61,17 +60,13 @@ public function homepage() $template = $this->getTemplateForPage($page); - $alternate = $this->getAlternateMetaData($page); - - return view($template, compact('page', 'alternate')); + return view($template, compact('page')); } /** * Find a page for the given slug. * The slug can be a 'composed' slug via the Menu - * * @param string $slug - * * @return Page */ private function findPageForSlug($slug) @@ -88,9 +83,7 @@ private function findPageForSlug($slug) /** * Return the template for the given page * or the default template if none found - * * @param $page - * * @return string */ private function getTemplateForPage($page) @@ -99,33 +92,13 @@ private function getTemplateForPage($page) } /** - * Throw a 404 error page if the given page is not found - * + * Throw a 404 error page if the given page is not found or draft * @param $page */ private function throw404IfNotFound($page) { - if (is_null($page)) { + if (null === $page || $page->status === $this->disabledPage) { $this->app->abort('404'); } } - - /** - * Create a key=>value array for alternate links - * - * @param $page - * - * @return array - */ - private function getAlternateMetaData($page) - { - $translations = $page->getTranslationsArray(); - - $alternate = []; - foreach ($translations as $locale => $data) { - $alternate[$locale] = $data['slug']; - } - - return $alternate; - } } diff --git a/Themes/Flatly/views/layouts/master.blade.php b/Themes/Flatly/views/layouts/master.blade.php index ab5030f9d..844544e6e 100644 --- a/Themes/Flatly/views/layouts/master.blade.php +++ b/Themes/Flatly/views/layouts/master.blade.php @@ -3,14 +3,12 @@ @section('meta') - + @show - @section('title')@setting('core::site-name')@show - @foreach($alternate as $alternateLocale=>$alternateSlug) - - @endforeach - + + @section('title')@setting('core::site-name')@show + {!! Theme::style('css/main.css') !!} @@ -32,7 +30,7 @@ @yield('scripts') -{!! Setting::get('core::analytics-script') !!} + {!! Setting::get('core::analytics-script') !!} @stack('js-stack') From 45f70f6761dba80bc246eb041449eb04d26763b2 Mon Sep 17 00:00:00 2001 From: Christian Giupponi Date: Wed, 1 Aug 2018 18:01:09 +0200 Subject: [PATCH 3/4] Add canonical and metadata for pages --- .../Http/Controllers/PublicController.php | 23 +++++++++++++++++++ Themes/Flatly/views/layouts/master.blade.php | 12 ++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Modules/Page/Http/Controllers/PublicController.php b/Modules/Page/Http/Controllers/PublicController.php index 7c23ef337..a2fc14cb1 100644 --- a/Modules/Page/Http/Controllers/PublicController.php +++ b/Modules/Page/Http/Controllers/PublicController.php @@ -46,6 +46,8 @@ public function uri($slug) $template = $this->getTemplateForPage($page); + $alternate = $this->getAlternateMetaData($page); + return view($template, compact('page')); } @@ -60,6 +62,8 @@ public function homepage() $template = $this->getTemplateForPage($page); + $alternate = $this->getAlternateMetaData($page); + return view($template, compact('page')); } @@ -101,4 +105,23 @@ private function throw404IfNotFound($page) $this->app->abort('404'); } } + + /** + * Create a key=>value array for alternate links + * + * @param $page + * + * @return array + */ + private function getAlternateMetaData($page) + { + $translations = $page->getTranslationsArray(); + + $alternate = []; + foreach ($translations as $locale => $data) { + $alternate[$locale] = $data['slug']; + } + + return $alternate; + } } diff --git a/Themes/Flatly/views/layouts/master.blade.php b/Themes/Flatly/views/layouts/master.blade.php index 844544e6e..ab5030f9d 100644 --- a/Themes/Flatly/views/layouts/master.blade.php +++ b/Themes/Flatly/views/layouts/master.blade.php @@ -3,12 +3,14 @@ @section('meta') - + @show - - @section('title')@setting('core::site-name')@show - + @section('title')@setting('core::site-name')@show + @foreach($alternate as $alternateLocale=>$alternateSlug) + + @endforeach + {!! Theme::style('css/main.css') !!} @@ -30,7 +32,7 @@ @yield('scripts') - {!! Setting::get('core::analytics-script') !!} +{!! Setting::get('core::analytics-script') !!} @stack('js-stack') From ea3399795feceeb9ee8102eb27b9019e289332bd Mon Sep 17 00:00:00 2001 From: Christian Giupponi Date: Thu, 2 Aug 2018 09:44:12 +0200 Subject: [PATCH 4/4] Pass to the view --- Modules/Page/Http/Controllers/PublicController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Page/Http/Controllers/PublicController.php b/Modules/Page/Http/Controllers/PublicController.php index a2fc14cb1..88a958b1c 100644 --- a/Modules/Page/Http/Controllers/PublicController.php +++ b/Modules/Page/Http/Controllers/PublicController.php @@ -48,7 +48,7 @@ public function uri($slug) $alternate = $this->getAlternateMetaData($page); - return view($template, compact('page')); + return view($template, compact('page', 'alternate')); } /** @@ -64,7 +64,7 @@ public function homepage() $alternate = $this->getAlternateMetaData($page); - return view($template, compact('page')); + return view($template, compact('page', 'alternate')); } /**