routing fixed

This commit is contained in:
Sergey Yarkov 2026-02-25 10:02:06 +03:00
parent f3e4b3b9d8
commit adf3238fe3
16 changed files with 47 additions and 26 deletions

View File

@ -5,27 +5,26 @@ import UIString from "./UIString.astro";
import { getLanguageFromURL } from "../i18n/utils";
const pageLang = getLanguageFromURL(Astro.url.pathname);
console.log(pageLang);
---
<footer>
<div class='container'>
<div class="container">
<div>
<i>
<UIString key={"footer.developed"} />: <TranslatedLink to='/contacts/'> Sergey Yarkov </TranslatedLink>
<UIString key={"footer.developed"} />: <TranslatedLink to="/contacts/"> Sergey Yarkov </TranslatedLink>
&copy; {new Date().getFullYear()}
</i>
</div>
<div>
<a href=`/${pageLang}/rss.xml` target='_blank'><UIString key={"footer.rssFeed"} /></a>
<a href=`/${pageLang}/rss.xml` target="_blank"><UIString key={"footer.rssFeed"} /></a>
<span>
<Icon name='rss' width='20' height='20' />
<Icon name="rss" width="20" height="20" />
</span>
</div>
</div>
</footer>
<style lang='scss'>
<style lang="scss">
footer {
font-weight: 500;
margin-top: 5rem;

View File

@ -17,8 +17,17 @@ export function getLanguageFromURL(pathname: string): LanguageKeys {
return DEFAULT_LANGUAGE;
}
// Call only from ./src/[lang]/page.astro
export function isPageLangSupported(Astro: Readonly<AstroGlobal>) {
const params = Astro.params as { lang: string };
if (SUPPORTED_LANGUAGES.includes(params.lang as LanguageKeys)) return true;
return false;
}
export function removeLangFromURL(pathname: string): string {
return pathname.split("/").slice(2).join("/");
const splittedPath = pathname.split("/");
if (splittedPath.length >= 3) return "/" + splittedPath.slice(2).join("/");
return pathname;
}
function transformExports<T>(modules: Record<string, { default: T }>) {

View File

@ -14,10 +14,7 @@ const { title, description, lang = DEFAULT_LANGUAGE, noIndex = false } = Astro.p
---
<html lang={lang}>
<BaseHead
title={title ? `${title} | ${SITE_METADATA.title}` : SITE_METADATA.title}
description={description}
>
<BaseHead title={title ? `${title} | ${SITE_METADATA.title}` : SITE_METADATA.title} description={description}>
{noIndex && <meta name="robots" content="noindex" />}
</BaseHead>
<BaseLayout>

View File

@ -1,5 +1,5 @@
---
import NotFoundPage from "@templates/NotFound.astro";
import NotFoundTemplate from "@templates/NotFound.astro";
---
<NotFoundPage />
<NotFoundTemplate />

View File

@ -1,5 +1,8 @@
---
import AboutTemplate from "@templates/About.astro";
import { isPageLangSupported } from "@i18n/utils";
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
---
<AboutTemplate />

View File

@ -1,5 +1,8 @@
---
import ArticlesTemplate from "@templates/Articles.astro";
import { isPageLangSupported } from "@i18n/utils";
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
---
<ArticlesTemplate />

View File

@ -1,5 +1,8 @@
---
import ContactsTemplate from "@templates/Contacts.astro";
import { isPageLangSupported } from "@i18n/utils";
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
---
<ContactsTemplate />

View File

@ -1,5 +1,8 @@
---
import HomeTemplate from "@templates/Home.astro";
import { isPageLangSupported } from "@i18n/utils";
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
---
<HomeTemplate />

View File

@ -1,5 +1,8 @@
---
import ProjectsTemplate from "@templates/Projects.astro";
import { isPageLangSupported } from "@i18n/utils";
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
---
<ProjectsTemplate />

View File

@ -1,5 +1,5 @@
---
import AboutPage from "@templates/About.astro";
import AboutTemplate from "@templates/About.astro";
---
<AboutPage />
<AboutTemplate />

View File

@ -1,5 +1,5 @@
---
import ArticlesPage from "@templates/Articles.astro";
import ArticlesTemplate from "@templates/Articles.astro";
---
<ArticlesPage />
<ArticlesTemplate />

View File

@ -2,7 +2,8 @@
import ArticleLayout from "@root/layouts/article.astro";
import { getArticleTranslationsBySlug, incArticleTranslationViews } from "@/src/queries";
const { url } = Astro.params as { blog: string; url: string };
// Example of an URL: https://website.com/blog/01-01-2025/my-article/
const { url } = Astro.params as { url: string };
const slug = url.split("/").at(-1);
if (!slug) return Astro.redirect("/404");

View File

@ -1,5 +1,5 @@
---
import ContactsPage from "@root/templates/Contacts.astro";
import ContactsTemplate from "@templates/Contacts.astro";
---
<ContactsPage />
<ContactsTemplate />

View File

@ -1,5 +1,5 @@
---
import Home from "@root/templates/Home.astro";
import HomeTemplate from "@templates/Home.astro";
---
<Home />
<HomeTemplate />

View File

@ -1,5 +1,5 @@
---
import ProjectsPage from "@root/templates/Projects.astro";
import ProjectsTemplate from "@templates/Projects.astro";
---
<ProjectsPage />
<ProjectsTemplate />

View File

@ -22,8 +22,8 @@ const t = useTranslation(Astro);
<p><UIString key={"splash.description"} /></p>
</SplashHeading>
<SplashLinks>
<SplashLink icon='information' href='/about/'><UIString key={"splash.about"} /></SplashLink>
<SplashLink icon='email_filled' href='/contacts/'>
<SplashLink icon="information" href="/about/"><UIString key={"splash.about"} /></SplashLink>
<SplashLink icon="email_filled" href="/contacts/">
<UIString key={"splash.contact"} />
</SplashLink>
</SplashLinks>