Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/components/LocaleRedirect.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
---
import { locales, defaultLocale } from "../i18n/locales.js";
const { path } = Astro.props;
const { path, noindex = false } = Astro.props;
const base = import.meta.env.BASE_URL;
const fallback = `${ base }${ defaultLocale }/${ path }`;
const canonical = new URL(fallback, Astro.site).href;
---
<noscript><meta http-equiv="refresh" content={ `0;url=${ fallback }` } /></noscript>
<script define:vars={{ locales, defaultLocale, base, path }}>
const preferred = navigator.languages
.map(tag => tag.split("-")[0].toLowerCase())
.find(lang => locales.includes(lang));
location.replace(`${ base }${ preferred ?? defaultLocale }/${ path }${ location.search }${ location.hash }`);
</script>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Redirecting to: { canonical }</title>
<noscript><meta http-equiv="refresh" content={ `0;url=${ fallback }` } /></noscript>
{ noindex && <meta name="robots" content="noindex" /> }
<link rel="canonical" href={ canonical } />
</head>
<body>
<script define:vars={{ locales, defaultLocale, base, path }}>
const preferred = navigator.languages
.map(tag => tag.split("-")[0].toLowerCase())
.find(lang => locales.includes(lang));
location.replace(`${ base }${ preferred ?? defaultLocale }/${ path }${ location.search }${ location.hash }`);
</script>
</body>
</html>
18 changes: 16 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
---
import { Font } from "astro:assets";
import { getRelativeLocaleUrl } from "astro:i18n";
import "../styles/global.css";
import Header from "../components/Header.astro";
import HeroBlob from "../components/blobs/HeroBlob.astro";
import { t } from "../i18n/utils.js";
import { defaultLocale, locales, bcp47Locale } from "../i18n/locales.js";

const { title, description, blob = false, illustration } = Astro.props;
const lang = Astro.currentLocale;
const { title, description, blob = false, illustration, noindex = false } = Astro.props;
const lang = Astro.currentLocale ?? defaultLocale;

// Same locale-stripping approach as LanguagePicker.astro, so canonical/hreflang
// stay consistent with the language switcher's own URL generation.
const withoutBase = Astro.url.pathname.slice(import.meta.env.BASE_URL.length);
const currentPath = "/" + withoutBase.split("/").filter(Boolean).slice(1).join("/");
const localizedUrl = (locale: string) => new URL(getRelativeLocaleUrl(locale, currentPath), Astro.site);
---

<!doctype html>
Expand All @@ -16,6 +24,12 @@ const lang = Astro.currentLocale;
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content={ description ?? t(lang, "site.description") } />
<title>{ title ?? t(lang, "site.title") }</title>
{ noindex && <meta name="robots" content="noindex" /> }
<link rel="canonical" href={ localizedUrl(lang).href } />
{ locales.map((locale) => (
<link rel="alternate" hreflang={ bcp47Locale[locale] } href={ localizedUrl(locale).href } />
)) }
<link rel="alternate" hreflang="x-default" href={ localizedUrl(defaultLocale).href } />
<link rel="icon" type="image/svg+xml" href={`${ import.meta.env.BASE_URL }favicon.svg`} />
<link rel="icon" type="image/x-icon" href={`${ import.meta.env.BASE_URL }favicon.ico`} />
<link rel="apple-touch-icon" href={`${ import.meta.env.BASE_URL }apple-touch-icon.png`} />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[lang]/add/catalog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const retryLinkSlots: Record<string, LinkSlot & { id: string }> = {
};
---

<Layout title={ t(lang, "add.catalog.title") + " — " + t(lang, "site.title") }>
<Layout title={ t(lang, "add.catalog.title") + " — " + t(lang, "site.title") } noindex>
<div class="page-intro">
<h1>{ t(lang, "add.catalog.title") }</h1>
<div id="intro-body">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[lang]/add/publication.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const retryLinkSlots: Record<string, LinkSlot & { id: string }> = {
};
---

<Layout title={ t(lang, "add.publication.title") + " — " + t(lang, "site.title") }>
<Layout title={ t(lang, "add.publication.title") + " — " + t(lang, "site.title") } noindex>
<div class="page-intro">
<h1>{ t(lang, "add.publication.title") }</h1>
<div id="intro-body">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/add/catalog.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
import LocaleRedirect from "../../components/LocaleRedirect.astro";
---
<LocaleRedirect path="add/catalog" />
<LocaleRedirect path="add/catalog" noindex />
2 changes: 1 addition & 1 deletion src/pages/add/publication.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
import LocaleRedirect from "../../components/LocaleRedirect.astro";
---
<LocaleRedirect path="add/publication" />
<LocaleRedirect path="add/publication" noindex />
4 changes: 3 additions & 1 deletion src/sitemap-allowlist.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[
{ "path": "/", "locales": "*" },
{ "path": "/download/", "locales": "*" },
{ "path": "/release-notes/desktop/\\d+-\\d+-\\d+/", "locales": ["en"] },
{ "path": "/guides/.*", "locales": ["en"] },
{ "path": "/release-notes/desktop/\\d+-\\d+-\\d+/", "locales": "*" },
{ "path": "/release-notes/ios/\\d+-\\d+-\\d+/", "locales": "*" }
]