Skip to content

Commit 13d4214

Browse files
committed
Follow Google guidelines for localized versions of pages
1 parent 9bf96e3 commit 13d4214

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-sitemappable` will be documented in this file
44

5+
## 1.1.0 - 2021-10-21
6+
7+
- Follow Google guidelines for localized versions of pages.
8+
59
## 1.0.0 - 2021-05-17
610

711
- initial release.

resources/views/sitemap.blade.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{!! '<' . '?xml version="1.0" encoding="UTF-8"?>' !!}
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
33
@foreach ($sitemappables as $sitemappable)
4-
<url>
5-
<loc>{{ $sitemappable->urls[array_key_first($sitemappable->urls)] }}</loc>
6-
@foreach ($sitemappable->urls as $lang => $url)
7-
<xhtml:link rel="alternate" hreflang="{{ $lang }}" href="{{ $url }}"></xhtml:link>
8-
@endforeach
9-
@if ($sitemappable->updated_at)
10-
<lastmod>{{ $sitemappable->updated_at->toIso8601String() }}</lastmod>
11-
@endif
12-
</url>
4+
@foreach ($sitemappable->urls as $url)
5+
<url>
6+
<loc>{{ $url }}</loc>
7+
@if (count(array_keys($sitemappable->urls)) > 1)
8+
@foreach ($sitemappable->urls as $lang => $url)
9+
<xhtml:link rel="alternate" hreflang="{{ $lang }}" href="{{ $url }}"></xhtml:link>
10+
@endforeach
11+
@endif
12+
@if ($sitemappable->updated_at)
13+
<lastmod>{{ $sitemappable->updated_at->toIso8601String() }}</lastmod>
14+
@endif
15+
</url>
16+
@endforeach
1317
@endforeach
1418
</urlset>

tests/SitemappableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public function test_it_can_generate_an_xml_sitemap()
9292
<xhtml:link rel="alternate" hreflang="en" href="https://www.vursion.io/en/tests/test-slug-in-english"></xhtml:link>
9393
<lastmod>' . $testModel->updated_at->toIso8601String() . '</lastmod>
9494
</url>
95+
<url>
96+
<loc>https://www.vursion.io/en/tests/test-slug-in-english</loc>
97+
<xhtml:link rel="alternate" hreflang="nl" href="https://www.vursion.io/nl/testen/test-slug-in-het-nederlands"></xhtml:link>
98+
<xhtml:link rel="alternate" hreflang="en" href="https://www.vursion.io/en/tests/test-slug-in-english"></xhtml:link>
99+
<lastmod>' . $testModel->updated_at->toIso8601String() . '</lastmod>
100+
</url>
95101
</urlset>');
96102

97103
$this->assertXmlStringEqualsXmlString($expected, $response->getContent());

0 commit comments

Comments
 (0)