forked from auxolotl/website
fix: infer type of getStaticPaths
This commit is contained in:
parent
610fa12723
commit
e6faf8ca98
|
@ -2,10 +2,11 @@
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
import { useTranslations } from "../i18n/utils";
|
import { useTranslations } from "../i18n/utils";
|
||||||
|
import type { Params } from "../i18n/utils";
|
||||||
import { Image } from "astro:assets";
|
import { Image } from "astro:assets";
|
||||||
import aux from "../../public/aux.svg";
|
import aux from "../../public/aux.svg";
|
||||||
|
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
const translation = useTranslations(lang);
|
const translation = useTranslations(lang);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
---
|
---
|
||||||
import { useTranslations } from "../../i18n/utils";
|
import { useTranslations } from "../../i18n/utils";
|
||||||
|
import type { Params } from "../../i18n/utils";
|
||||||
|
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
const translation = useTranslations(lang);
|
const translation = useTranslations(lang);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
import { useTranslations } from "../../i18n/utils";
|
import { useTranslations } from "../../i18n/utils";
|
||||||
import { Image } from "astro:assets";
|
import { Image } from "astro:assets";
|
||||||
import aux from "../../../public/aux.svg";
|
import aux from "../../../public/aux.svg";
|
||||||
|
import type { Params } from "../../i18n/utils";
|
||||||
|
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
const translation = useTranslations(lang);
|
const translation = useTranslations(lang);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
---
|
---
|
||||||
import { useTranslations } from "../../i18n/utils";
|
import { useTranslations } from "../../i18n/utils";
|
||||||
|
import type { Params } from "../../i18n/utils";
|
||||||
|
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
const translation = useTranslations(lang);
|
const translation = useTranslations(lang);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
---
|
---
|
||||||
import { useTranslations } from "../../i18n/utils";
|
import { useTranslations } from "../../i18n/utils";
|
||||||
|
import type { Params } from "../../i18n/utils";
|
||||||
|
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
const translation = useTranslations(lang);
|
const translation = useTranslations(lang);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
import { ui, defaultLang } from "./ui";
|
import { ui, defaultLang, languages } from "./ui";
|
||||||
|
import type {
|
||||||
|
InferGetStaticParamsType,
|
||||||
|
InferGetStaticPropsType,
|
||||||
|
GetStaticPaths,
|
||||||
|
} from "astro";
|
||||||
|
|
||||||
export function useTranslations(lang: keyof typeof ui) {
|
export function useTranslations(lang: keyof typeof ui) {
|
||||||
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
|
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
|
||||||
return ui[lang][key] || ui[defaultLang][key];
|
return ui[lang][key] || ui[defaultLang][key];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getStaticPaths = (async () => {
|
||||||
|
return Object.keys(languages).map((name) => ({
|
||||||
|
params: { lang: name as keyof typeof languages },
|
||||||
|
}));
|
||||||
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
|
export type Params = InferGetStaticParamsType<typeof getStaticPaths>;
|
||||||
|
export type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
---
|
---
|
||||||
import Header from "../components/Header.astro";
|
import Header from "../components/Header.astro";
|
||||||
|
import type { Params } from "../i18n/utils";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { title } = Astro.props;
|
const { title } = Astro.props;
|
||||||
const { lang } = Astro.params;
|
const { lang } = Astro.params as Params;
|
||||||
---
|
---
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
---
|
---
|
||||||
import { languages } from "../../i18n/ui";
|
|
||||||
import Layout from "../../layouts/Layout.astro";
|
import Layout from "../../layouts/Layout.astro";
|
||||||
import Home from "../../components/home/Home.astro";
|
import Home from "../../components/home/Home.astro";
|
||||||
|
export { getStaticPaths } from "../../i18n/utils";
|
||||||
export async function getStaticPaths() {
|
|
||||||
return Object.keys(languages).map((name) => ({ params: { lang: name } }));
|
|
||||||
}
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="auxolotl.org">
|
<Layout title="auxolotl.org">
|
||||||
|
|
Loading…
Reference in a new issue