Skip to content

Commit

Permalink
Add canonical and metadata for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
cgiupponi committed Aug 1, 2018
1 parent e46f790 commit 45f70f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
23 changes: 23 additions & 0 deletions Modules/Page/Http/Controllers/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function uri($slug)

$template = $this->getTemplateForPage($page);

$alternate = $this->getAlternateMetaData($page);

return view($template, compact('page'));
}

Expand All @@ -60,6 +62,8 @@ public function homepage()

$template = $this->getTemplateForPage($page);

$alternate = $this->getAlternateMetaData($page);

return view($template, compact('page'));
}

Expand Down Expand Up @@ -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;
}
}
12 changes: 7 additions & 5 deletions Themes/Flatly/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
<head lang="{{ LaravelLocalization::setLocale() }}">
<meta charset="UTF-8">
@section('meta')
<meta name="description" content="@setting('core::site-description')" />
<meta name="description" content="@setting('core::site-description')"/>
@show
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
@section('title')@setting('core::site-name')@show
</title>
<title>@section('title')@setting('core::site-name')@show</title>
@foreach($alternate as $alternateLocale=>$alternateSlug)
<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') }}">

{!! Theme::style('css/main.css') !!}
Expand All @@ -30,7 +32,7 @@
@yield('scripts')

<?php if (Setting::has('core::analytics-script')): ?>
{!! Setting::get('core::analytics-script') !!}
{!! Setting::get('core::analytics-script') !!}
<?php endif; ?>
@stack('js-stack')
</body>
Expand Down

0 comments on commit 45f70f6

Please sign in to comment.