Skip to content

Commit 49db344

Browse files
committed
Fixes unnecessary redirecting and langSelector
1 parent 2797d1d commit 49db344

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

astro.config.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default defineConfig({
1414
defaultLocale: "en",
1515
locales: ["es", "en"],
1616
routing: {
17-
prefixDefaultLocale: true,
17+
prefixDefaultLocale: false,
18+
redirectToDefaultLocale: true,
1819
},
1920
},
2021
});

src/components/LanguageSelector.astro

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { languages } from "../i18n/ui";
2828
>
2929
<ul>
3030
{
31-
Object.keys(languages).map((language) => (
31+
Object.keys(languages).map((languageCode) => (
3232
<li class="languages-menu-option px-2 py-1.5 cursor-default hover:bg-gray-500/50 rounded-sm">
33-
<a href={`/${languages[language]}/`}>{language}</a>
33+
<a href={`/${languageCode}/`}>{languages[languageCode]}</a>
3434
</li>
3535
))
3636
}
@@ -61,7 +61,7 @@ import { languages } from "../i18n/ui";
6161
const languagesMenu = document.getElementById("languages-menu");
6262

6363
const getLanguagePreference = () => {
64-
return window.location.pathname.replaceAll("/", "");
64+
return document.documentElement.lang;
6565
};
6666

6767
const updateIcon = (languagePreference) => {

src/pages/index.astro

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
import Layout from "../layouts/Layout.astro";
3+
import "../styles/global.css";
4+
import ExperienceTimeline from "../components/ExperienceTimeline.astro";
5+
import SectionContainer from "../components/SectionContainer.astro";
6+
import BriefCaseIcon from "../icons/BriefCase.astro";
7+
import Footer from "../components/Footer.astro";
8+
import CodeIcon from "../icons/Code.astro";
9+
import Projects from "../components/Projects.astro";
10+
import Intro from "../components/Intro.astro";
11+
import { getLangFromUrl, useTranslations } from "../i18n/utils";
12+
13+
const lang = getLangFromUrl(Astro.url);
14+
const t = useTranslations(lang);
15+
---
16+
17+
<Layout
18+
title={t("page.title") as string}
19+
description={t("page.description") as string}
20+
>
21+
<main class="px-4">
22+
<SectionContainer id="intro" class="pt-30 md:pt-44 pb-20 md:pb-30">
23+
<Intro />
24+
</SectionContainer>
25+
<SectionContainer id="experience">
26+
<h2
27+
class="text-xl md:text-3xl font-semibold mb-6 flex gap-x-3 items-center"
28+
>
29+
<BriefCaseIcon class="size-6 md:size-7" />
30+
{t("experiences.title")}
31+
</h2>
32+
<ExperienceTimeline />
33+
</SectionContainer>
34+
<SectionContainer id="projects">
35+
<h2
36+
class="text-xl md:text-3xl font-semibold mb-6 flex gap-x-3 items-center"
37+
>
38+
<CodeIcon class="size-6 md:size-7" />
39+
{t("projects.title")}
40+
</h2>
41+
<Projects />
42+
</SectionContainer>
43+
44+
<Footer />
45+
</main>
46+
</Layout>

0 commit comments

Comments
 (0)