Skip to content

Commit 6da094b

Browse files
committed
Remove JS redirect and improve SEO on multi-lang page
1 parent 2281597 commit 6da094b

3 files changed

Lines changed: 55 additions & 40 deletions

File tree

data/site.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@ author:
1414
name: 'Thibaud Guillaume-Gentil'
1515
email: 'thibaud@thibaud.gg'
1616
website: 'https://thibaud.gg'
17+
18+
jsonld:
19+
"@context": "http://schema.org"
20+
"@type": "WebSite"
21+
"url": "https://csa-admin.org"
22+
"inLanguage": "en"
23+
"potentialAction":
24+
"@type": "ReadAction"
25+
"target":
26+
- "@type": "EntryPoint"
27+
"urlTemplate": "https://csa-admin.org"
28+
"inLanguage": "en"
29+
- "@type": "EntryPoint"
30+
"urlTemplate": "https://csa-admin.org/acp"
31+
"inLanguage": "fr"
32+
- "@type": "EntryPoint"
33+
"urlTemplate": "https://csa-admin.org/solawi"
34+
"inLanguage": "de"
35+
36+

source/layouts/layout.slim

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,19 @@ html class='bg-white antialiased scroll-smooth' lang='fr'
88
meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'
99
meta name='Description' content = t('site.description')
1010
meta name='author' content = data.site.author.name
11+
meta name="robots" content="index, follow"
1112

12-
== auto_display_favicon_tags
13-
== stylesheet_link_tag 'site'
14-
15-
javascript:
16-
// Redirect to the correct language landing page
17-
javascript:
18-
document.addEventListener('DOMContentLoaded', function() {
19-
var languageRedirected = localStorage.getItem('languageRedirected')
20-
if (languageRedirected) {
21-
return
22-
}
23-
24-
var userAgent = navigator.userAgent.toLowerCase();
25-
if (/bot|crawl|spider|slurp|bing|msn|teoma|baidu|yandex|duckduckbot|facebot|ia_archiver/.test(userAgent)) {
26-
return;
27-
}
13+
link rel="canonical" href="https://csa-admin.org"
14+
link rel="alternate" hreflang="en" href="https://csa-admin.org"
15+
link rel="alternate" hreflang="fr" href="https://csa-admin.org/acp"
16+
link rel="alternate" hreflang="de" href="https://csa-admin.org/solawi"
17+
link rel="alternate" hreflang="x-default" href="https://csa-admin.org"
2818

29-
localStorage.setItem('languageRedirected', true)
30-
var browserLanguage = navigator.language ? navigator.language.slice(0, 2) : null
19+
script type="application/ld+json"
20+
== data.site.jsonld.to_json
3121

32-
if (!browserLanguage || window.location.pathname !== '/') {
33-
return
34-
}
35-
36-
switch (browserLanguage) {
37-
case 'fr':
38-
window.location.pathname = '/acp'
39-
break
40-
case 'de':
41-
window.location.pathname = '/solawi'
42-
break
43-
}
44-
})
22+
== auto_display_favicon_tags
23+
== stylesheet_link_tag 'site'
4524

4625
body class='font-sans md:mx-auto md:max-w-7xl'
4726
.wrapper class="mx-4 md:mx-12"

source/sitemap.xml.builder

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
xml.instruct!
2-
xml.urlset 'xmlns' => "http://www.sitemaps.org/schemas/sitemap/0.9" do
3-
sitemap.resources.select { |page| page.path =~ /\.html/ }.each do |page|
4-
path = page.destination_path == "index.html" ? "" : "/#{page.destination_path}"
5-
xml.url do
6-
xml.loc "https://csa-admin.org#{path}"
7-
xml.changefreq "weekly"
8-
xml.priority path.blank? ? "1.0" : "0.5"
9-
end
1+
xml.instruct! :xml, version: "1.0", encoding: "UTF-8"
2+
xml.urlset("xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9", "xmlns:xhtml" => "http://www.w3.org/1999/xhtml") do
3+
xml.url do
4+
xml.loc "https://csa-admin.org"
5+
xml.changefreq "weekly"
6+
xml.priority "1.0"
7+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "fr", href: "https://csa-admin.org/acp")
8+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "de", href: "https://csa-admin.org/solawi")
9+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "x-default", href: "https://csa-admin.org")
10+
end
11+
12+
xml.url do
13+
xml.loc "https://csa-admin.org/acp"
14+
xml.changefreq "weekly"
15+
xml.priority "0.9"
16+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "en", href: "https://csa-admin.org")
17+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "de", href: "https://csa-admin.org/solawi")
18+
end
19+
20+
xml.url do
21+
xml.loc "https://csa-admin.org/solawi"
22+
xml.changefreq "weekly"
23+
xml.priority "0.9"
24+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "en", href: "https://csa-admin.org")
25+
xml.tag!("xhtml:link", rel: "alternate", hreflang: "fr", href: "https://csa-admin.org/acp")
1026
end
1127
end

0 commit comments

Comments
 (0)