Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
3159cae9
Commit
3159cae9
authored
Aug 01, 2018
by
Christian Giupponi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add canonical url and alternate links for each language available
parent
785f1b29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
12 deletions
+41
-12
PublicController.php
Modules/Page/Http/Controllers/PublicController.php
+34
-7
master.blade.php
Themes/Flatly/views/layouts/master.blade.php
+7
-5
No files found.
Modules/Page/Http/Controllers/PublicController.php
View file @
3159cae9
...
@@ -19,17 +19,16 @@ class PublicController extends BasePublicController
...
@@ -19,17 +19,16 @@ class PublicController extends BasePublicController
*/
*/
private
$app
;
private
$app
;
private
$disabledPage
=
false
;
public
function
__construct
(
PageRepository
$page
,
Application
$app
)
public
function
__construct
(
PageRepository
$page
,
Application
$app
)
{
{
parent
::
__construct
();
parent
::
__construct
();
$this
->
page
=
$page
;
$this
->
page
=
$page
;
$this
->
app
=
$app
;
$this
->
app
=
$app
;
}
}
/**
/**
* @param $slug
* @param $slug
*
* @return \Illuminate\View\View
* @return \Illuminate\View\View
*/
*/
public
function
uri
(
$slug
)
public
function
uri
(
$slug
)
...
@@ -46,7 +45,9 @@ class PublicController extends BasePublicController
...
@@ -46,7 +45,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,13 +61,17 @@ class PublicController extends BasePublicController
...
@@ -60,13 +61,17 @@ 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'
));
}
}
/**
/**
* Find a page for the given slug.
* Find a page for the given slug.
* The slug can be a 'composed' slug via the Menu
* The slug can be a 'composed' slug via the Menu
*
* @param string $slug
* @param string $slug
*
* @return Page
* @return Page
*/
*/
private
function
findPageForSlug
(
$slug
)
private
function
findPageForSlug
(
$slug
)
...
@@ -83,7 +88,9 @@ class PublicController extends BasePublicController
...
@@ -83,7 +88,9 @@ class PublicController extends BasePublicController
/**
/**
* Return the template for the given page
* Return the template for the given page
* or the default template if none found
* or the default template if none found
*
* @param $page
* @param $page
*
* @return string
* @return string
*/
*/
private
function
getTemplateForPage
(
$page
)
private
function
getTemplateForPage
(
$page
)
...
@@ -92,13 +99,33 @@ class PublicController extends BasePublicController
...
@@ -92,13 +99,33 @@ class PublicController extends BasePublicController
}
}
/**
/**
* 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
* @param $page
*/
*/
private
function
throw404IfNotFound
(
$page
)
private
function
throw404IfNotFound
(
$page
)
{
{
if
(
null
===
$page
||
$page
->
status
===
$this
->
disabledPage
)
{
if
(
is_null
(
$page
)
)
{
$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
;
}
}
}
Themes/Flatly/views/layouts/master.blade.php
View file @
3159cae9
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment