Unverified Commit 0562bc8d authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #569 from ChristianGiupponi/3.0

Add canonical and Alternate link
parents adbca712 ea339979
...@@ -46,7 +46,9 @@ class PublicController extends BasePublicController ...@@ -46,7 +46,9 @@ class PublicController extends BasePublicController
$template = $this->getTemplateForPage($page); $template = $this->getTemplateForPage($page);
return view($template, compact('page')); $alternate = $this->getAlternateMetaData($page);
return view($template, compact('page', 'alternate'));
} }
/** /**
...@@ -60,7 +62,9 @@ class PublicController extends BasePublicController ...@@ -60,7 +62,9 @@ class PublicController extends BasePublicController
$template = $this->getTemplateForPage($page); $template = $this->getTemplateForPage($page);
return view($template, compact('page')); $alternate = $this->getAlternateMetaData($page);
return view($template, compact('page', 'alternate'));
} }
/** /**
...@@ -101,4 +105,23 @@ class PublicController extends BasePublicController ...@@ -101,4 +105,23 @@ class PublicController extends BasePublicController
$this->app->abort('404'); $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;
}
} }
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
<head lang="{{ LaravelLocalization::setLocale() }}"> <head lang="{{ LaravelLocalization::setLocale() }}">
<meta charset="UTF-8"> <meta charset="UTF-8">
@section('meta') @section('meta')
<meta name="description" content="@setting('core::site-description')" /> <meta name="description" content="@setting('core::site-description')"/>
@show @show
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title> <title>@section('title')@setting('core::site-name')@show</title>
@section('title')@setting('core::site-name')@show @foreach($alternate as $alternateLocale=>$alternateSlug)
</title> <link rel="alternate" hreflang="{{$alternateLocale}}" href="{{url($alternateLocale.'/'.$alternateSlug)}}">
@endforeach
<link rel="canonical" href="{{url()->current()}}" />
<link rel="shortcut icon" href="{{ Theme::url('favicon.ico') }}"> <link rel="shortcut icon" href="{{ Theme::url('favicon.ico') }}">
{!! Theme::style('css/main.css') !!} {!! Theme::style('css/main.css') !!}
...@@ -30,7 +32,7 @@ ...@@ -30,7 +32,7 @@
@yield('scripts') @yield('scripts')
<?php if (Setting::has('core::analytics-script')): ?> <?php if (Setting::has('core::analytics-script')): ?>
{!! Setting::get('core::analytics-script') !!} {!! Setting::get('core::analytics-script') !!}
<?php endif; ?> <?php endif; ?>
@stack('js-stack') @stack('js-stack')
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment