mirror of
https://github.com/sergeyyarkov/yarkov.tech.git
synced 2026-10-11 18:39:14 +03:00
routing fixed
This commit is contained in:
parent
f3e4b3b9d8
commit
adf3238fe3
@ -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>
|
||||
© {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;
|
||||
|
||||
@ -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 }>) {
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import NotFoundPage from "@templates/NotFound.astro";
|
||||
import NotFoundTemplate from "@templates/NotFound.astro";
|
||||
---
|
||||
|
||||
<NotFoundPage />
|
||||
<NotFoundTemplate />
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
---
|
||||
import AboutTemplate from "@templates/About.astro";
|
||||
import { isPageLangSupported } from "@i18n/utils";
|
||||
|
||||
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
|
||||
---
|
||||
|
||||
<AboutTemplate />
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
---
|
||||
import ArticlesTemplate from "@templates/Articles.astro";
|
||||
import { isPageLangSupported } from "@i18n/utils";
|
||||
|
||||
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
|
||||
---
|
||||
|
||||
<ArticlesTemplate />
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
---
|
||||
import ContactsTemplate from "@templates/Contacts.astro";
|
||||
import { isPageLangSupported } from "@i18n/utils";
|
||||
|
||||
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
|
||||
---
|
||||
|
||||
<ContactsTemplate />
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
---
|
||||
import HomeTemplate from "@templates/Home.astro";
|
||||
import { isPageLangSupported } from "@i18n/utils";
|
||||
|
||||
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
|
||||
---
|
||||
|
||||
<HomeTemplate />
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
---
|
||||
import ProjectsTemplate from "@templates/Projects.astro";
|
||||
import { isPageLangSupported } from "@i18n/utils";
|
||||
|
||||
if (!isPageLangSupported(Astro)) return Astro.redirect("/404");
|
||||
---
|
||||
|
||||
<ProjectsTemplate />
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import AboutPage from "@templates/About.astro";
|
||||
import AboutTemplate from "@templates/About.astro";
|
||||
---
|
||||
|
||||
<AboutPage />
|
||||
<AboutTemplate />
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import ArticlesPage from "@templates/Articles.astro";
|
||||
import ArticlesTemplate from "@templates/Articles.astro";
|
||||
---
|
||||
|
||||
<ArticlesPage />
|
||||
<ArticlesTemplate />
|
||||
|
||||
@ -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");
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import ContactsPage from "@root/templates/Contacts.astro";
|
||||
import ContactsTemplate from "@templates/Contacts.astro";
|
||||
---
|
||||
|
||||
<ContactsPage />
|
||||
<ContactsTemplate />
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import Home from "@root/templates/Home.astro";
|
||||
import HomeTemplate from "@templates/Home.astro";
|
||||
---
|
||||
|
||||
<Home />
|
||||
<HomeTemplate />
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import ProjectsPage from "@root/templates/Projects.astro";
|
||||
import ProjectsTemplate from "@templates/Projects.astro";
|
||||
---
|
||||
|
||||
<ProjectsPage />
|
||||
<ProjectsTemplate />
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user