Middleware modifications #1
@ -9,7 +9,7 @@ import react from "@astrojs/react";
|
|||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
output: "server",
|
output: "hybrid",
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: "standalone",
|
mode: "standalone",
|
||||||
}),
|
}),
|
||||||
@ -45,7 +45,10 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultLocale: "en",
|
defaultLocale: "en",
|
||||||
routing: "manual",
|
routing: {
|
||||||
|
redirectToDefaultLocale: true,
|
||||||
|
prefixDefaultLocale: true
|
||||||
|
},
|
||||||
fallback: {
|
fallback: {
|
||||||
de: "en",
|
de: "en",
|
||||||
fr: "en",
|
fr: "en",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
export const prerender = true;
|
export const prerender = false;
|
||||||
import SingleCompositionCard from "./SingleCompositionCard.astro";
|
import SingleCompositionCard from "./SingleCompositionCard.astro";
|
||||||
import { Separator } from "./ui/separator";
|
import { Separator } from "./ui/separator";
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
export const prerender = true;
|
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import {
|
|||||||
} from "./ui/tooltip"
|
} from "./ui/tooltip"
|
||||||
|
|
||||||
export function NavButton({ selected, variant, tooltip }) {
|
export function NavButton({ selected, variant, tooltip }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
export const prerender = true;
|
export const prerender = false;
|
||||||
import { ThemeSelector } from "./ThemeSelector"
|
import { ThemeSelector } from "./ThemeSelector"
|
||||||
import NavbarSkeleton from "./NavbarSkeleton.astro";
|
import NavbarSkeleton from "./NavbarSkeleton.astro";
|
||||||
import { LangSwitcher } from "./LangSwitcher";
|
import { LangSwitcher } from "./LangSwitcher";
|
||||||
@ -32,7 +32,7 @@ const t = useTranslations(getLangFromUrl(Astro.url));
|
|||||||
<NavButton selected={selected("/blog")} variant="blog" tooltip={t("navbar")["blog"]} client:load />
|
<NavButton selected={selected("/blog")} variant="blog" tooltip={t("navbar")["blog"]} client:load />
|
||||||
</a>
|
</a>
|
||||||
<a href={`/${locale}/music`}>
|
<a href={`/${locale}/music`}>
|
||||||
<NavButton selected={selected("/music")} variant="music" tooltip={t("navbar")["music"]} client:load/>
|
<NavButton selected={selected("/music")} variant="music" tooltip={t("navbar")["music"]} client:load />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import SinglePostCard from "./SinglePostCard.astro";
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
import SinglePostCard from "./SinglePostCard.astro";
|
||||||
const { filteredPosts } = Astro.props;
|
const { filteredPosts } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -13,8 +13,6 @@ import {
|
|||||||
TabsTrigger,
|
TabsTrigger,
|
||||||
} from "../components/ui/tabs";
|
} from "../components/ui/tabs";
|
||||||
|
|
||||||
export const prerender = true;
|
|
||||||
|
|
||||||
export function ShowcaseTabs({ currentLocale }) {
|
export function ShowcaseTabs({ currentLocale }) {
|
||||||
const t = useTranslations(currentLocale);
|
const t = useTranslations(currentLocale);
|
||||||
const showcase = t("showcase");
|
const showcase = t("showcase");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
export const prerender = true;
|
export const prerender = false;
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
|
@ -17,8 +17,6 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "./ui/tooltip"
|
} from "./ui/tooltip"
|
||||||
|
|
||||||
export const prerender = true;
|
|
||||||
|
|
||||||
// Please note that clang = lang, it's just for more confusion
|
// Please note that clang = lang, it's just for more confusion
|
||||||
export function ThemeSelector({ tooltip }) {
|
export function ThemeSelector({ tooltip }) {
|
||||||
function getTheme() {
|
function getTheme() {
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
import { defineMiddleware, sequence } from "astro:middleware";
|
|
||||||
import { middleware } from "astro:i18n"; // Astro's own i18n routing config
|
|
||||||
|
|
||||||
export const prerender = false
|
|
||||||
|
|
||||||
const langs = ["en", "de", "cs", "fr"]
|
|
||||||
|
|
||||||
export const userMiddleware = defineMiddleware((ctx, next) => {
|
|
||||||
|
|
||||||
const exceptions = ["/api", "/public"]
|
|
||||||
|
|
||||||
// If path is in exceptions (i.e. api or public) return default middleware to handle it
|
|
||||||
if (exceptions.includes(ctx.url.pathname) ) {
|
|
||||||
return next();
|
|
||||||
|
|
||||||
// If no lang is set => set to english (some pages are language-les exceptions)
|
|
||||||
} else if ( !langs.some(item => ctx.url.href.includes(item)) ) {
|
|
||||||
return Response.redirect(`${ctx.url.protocol}${ctx.url.host}/en${ctx.url.pathname}`);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const onRequest = sequence(
|
|
||||||
userMiddleware,
|
|
||||||
middleware({
|
|
||||||
redirectToDefaultLocale: false,
|
|
||||||
prefixDefaultLocale: true,
|
|
||||||
})
|
|
||||||
);
|
|
@ -8,7 +8,7 @@ import PostsList from "../../../components/PostsList.astro";
|
|||||||
import { getLangFromUrl, useTranslations } from "../../../i18n/utils";
|
import { getLangFromUrl, useTranslations } from "../../../i18n/utils";
|
||||||
import { Separator } from "../../../components/ui/separator";
|
import { Separator } from "../../../components/ui/separator";
|
||||||
|
|
||||||
const t = useTranslations(getLangFromUrl(Astro.url))
|
const t = useTranslations(getLangFromUrl(Astro.url));
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
return ["en", "fr", "cs", "de"].map((lang) => {
|
return ["en", "fr", "cs", "de"].map((lang) => {
|
||||||
@ -19,16 +19,23 @@ var posts = await getBlogPosts();
|
|||||||
var filtered_posts = posts.filter(
|
var filtered_posts = posts.filter(
|
||||||
(post) => post.data.language == Astro.currentLocale,
|
(post) => post.data.language == Astro.currentLocale,
|
||||||
);
|
);
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<MainLayout title={t("blog")["title"]} description={t("blog")["description"]} lang={Astro.currentLocale}>
|
<MainLayout
|
||||||
|
title={t("blog")["title"]}
|
||||||
|
description={t("blog")["description"]}
|
||||||
|
lang={Astro.currentLocale}
|
||||||
|
>
|
||||||
<SinglePageBlogMode>
|
<SinglePageBlogMode>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<h4 class="mb-2 text-3xl font-semibold leading-none text-foreground">{t("blog")["visible"]}</h4>
|
<h4 class="mb-2 text-3xl font-semibold leading-none text-foreground">
|
||||||
<p class="mb-4 text-md leading-none text-foreground">{t("blog")["description"]}</p>
|
{t("blog")["visible"]}
|
||||||
<Separator className="my-4"/>
|
</h4>
|
||||||
<PostsList filteredPosts={filtered_posts} lang={Astro.currentLocale}/>
|
<p class="mb-4 text-md leading-none text-foreground">
|
||||||
|
{t("blog")["description"]}
|
||||||
|
</p>
|
||||||
|
<Separator className="my-4" />
|
||||||
|
<PostsList filteredPosts={filtered_posts} lang={Astro.currentLocale} />
|
||||||
</div>
|
</div>
|
||||||
</SinglePageBlogMode>
|
</SinglePageBlogMode>
|
||||||
</MainLayout>
|
</MainLayout>
|
@ -1,16 +1,12 @@
|
|||||||
---
|
---
|
||||||
export const prerender = true;
|
export const prerender = false;
|
||||||
|
|
||||||
import MainLayout from "../../../layouts/MainLayout.astro";
|
import MainLayout from "../../../layouts/MainLayout.astro";
|
||||||
|
import { getCompositions } from "../../../content/config";
|
||||||
//@ts-ignore
|
import SinglePageBlogMode from "../../../layouts/SinglePageBlogMode.astro";
|
||||||
|
import CompositionsList from "../../../components/CompositionsList.astro";
|
||||||
import { getLangFromUrl, useTranslations } from "../../../i18n/utils";
|
import { getLangFromUrl, useTranslations } from "../../../i18n/utils";
|
||||||
import { Separator } from "../../../components/ui/separator";
|
import { Separator } from "../../../components/ui/separator";
|
||||||
|
|
||||||
import SinglePageBlogMode from "../../../layouts/SinglePageBlogMode.astro";
|
|
||||||
import { getCompositions } from "../../../content/config";
|
|
||||||
import CompositionsList from "../../../components/CompositionsList.astro";
|
|
||||||
|
|
||||||
const t = useTranslations(getLangFromUrl(Astro.url));
|
const t = useTranslations(getLangFromUrl(Astro.url));
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
@ -19,22 +15,21 @@ export async function getStaticPaths() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const songs = await getCompositions()
|
var songs = await getCompositions()
|
||||||
|
songs = songs.reverse()
|
||||||
---
|
---
|
||||||
|
|
||||||
<MainLayout
|
<MainLayout
|
||||||
title={t("music")["pageTitle"]}
|
title={t("music")["pageTitle"]}
|
||||||
description={t("music")["description"]}
|
description={t("music")["description"]}
|
||||||
lang={Astro.currentLocale}
|
lang={Astro.currentLocale}
|
||||||
themeOverride="theme_auto"
|
|
||||||
>
|
>
|
||||||
<SinglePageBlogMode>
|
<SinglePageBlogMode>
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<h4 class="mb-2 text-3xl font-semibold leading-none text-foreground">{t("music")["title"]}</h4>
|
<h4 class="mb-2 text-3xl font-semibold leading-none text-foreground">{t("music")["title"]}</h4>
|
||||||
<p class="mb-4 text-md leading-none text-foreground">{t("music")["description"]}</p>
|
<p class="mb-4 text-md leading-none text-foreground">{t("music")["description"]}</p>
|
||||||
{ // @ts-ignore }
|
|
||||||
<Separator className="my-4"/>
|
<Separator className="my-4"/>
|
||||||
<CompositionsList songs={songs.reverse()}/>
|
<CompositionsList songs={songs}/>
|
||||||
</div>
|
</div>
|
||||||
</SinglePageBlogMode>
|
</SinglePageBlogMode>
|
||||||
</MainLayout>
|
</MainLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user