Skip to content

Commit

Permalink
Merge pull request #27 from stefandoorn/hreflang-output-fix
Browse files Browse the repository at this point in the history
Hreflang output fix (fixes #26)
  • Loading branch information
stefandoorn authored Oct 29, 2017
2 parents cf6d0db + d707bba commit fcb6c29
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Resources/views/show.xml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
{% for url in url_set %}
<url>
<loc>{{ url_helper.absolute_or_relative(url.localization, absolute_url) }}</loc>
{% if hreflang is not same as(false) %}
{% if hreflang is not same as(false) and url.alternatives is not empty %}
<xhtml:link rel="alternate" hreflang="{{ language_helper.localeToCode(sylius.localeCode) }}" href="{{ url_helper.absolute_or_relative(url.localization, absolute_url) }}"/>
{% for locale, location in url.alternatives %}
<xhtml:link rel="alternate" hreflang="{{ language_helper.localeToCode(locale) }}" href="{{ url_helper.absolute_or_relative(location, absolute_url) }}"/>
{% endfor %}
Expand All @@ -15,5 +16,19 @@
{{ xml_helper.change_frequency(url) }}
{{ xml_helper.priority(url) }}
</url>
{% if hreflang is not same as(false) and url.alternatives is not empty %}
{% for locale, location in url.alternatives %}
<url>
<loc>{{ url_helper.absolute_or_relative(location, absolute_url) }}</loc>
<xhtml:link rel="alternate" hreflang="{{ language_helper.localeToCode(sylius.localeCode) }}" href="{{ url_helper.absolute_or_relative(url.localization, absolute_url) }}"/>
{% for localeSub, locationSub in url.alternatives %}
<xhtml:link rel="alternate" hreflang="{{ language_helper.localeToCode(localeSub) }}" href="{{ url_helper.absolute_or_relative(locationSub, absolute_url) }}"/>
{% endfor %}
{{ xml_helper.last_modification(url) }}
{{ xml_helper.change_frequency(url) }}
{{ xml_helper.priority(url) }}
</url>
{% endfor %}
{% endif %}
{% endfor %}
</urlset>
18 changes: 18 additions & 0 deletions tests/Responses/Expected/show_sitemap_products_locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://localhost/en_US/products/test</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/products/test"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/products/test"/>
<lastmod>@string@.isDateTime()</lastmod>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/nl_NL/products/test</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/products/test"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/products/test"/>
<lastmod>@string@.isDateTime()</lastmod>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/en_US/products/mock</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/products/mock"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/products/mock"/>
<lastmod>@string@.isDateTime()</lastmod>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/nl_NL/products/mock</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/products/mock"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/products/mock"/>
<lastmod>@string@.isDateTime()</lastmod>
<changefreq>always</changefreq>
Expand Down
16 changes: 16 additions & 0 deletions tests/Responses/Expected/show_sitemap_taxons_locale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://localhost/en_US/taxons/test</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/taxons/test"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/taxons/test"/>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/nl_NL/taxons/test</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/taxons/test"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/taxons/test"/>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/en_US/taxons/mock</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/taxons/mock"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/taxons/mock"/>
<changefreq>always</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://localhost/nl_NL/taxons/mock</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://localhost/en_US/taxons/mock"/>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/nl_NL/taxons/mock"/>
<changefreq>always</changefreq>
<priority>0.5</priority>
Expand Down

0 comments on commit fcb6c29

Please sign in to comment.