Commit 1a885cf
Changed files (5)
src
src/components/Header.astro
@@ -1,7 +1,7 @@
---
import { getIntlayer, type Locale } from "intlayer";
import LocaleSwitcher from "@/components/widgets/LocaleSwitcher.astro";
-import { SITE_CONFIG } from "@/config.ts";
+import { DEFAULT_LOCALE, SITE_CONFIG } from "@/config.ts";
import { getRelativeLocaleUrl } from "@/utils/url.ts";
interface Props {
@@ -9,7 +9,7 @@ interface Props {
}
const { availableLocales } = Astro.props;
-const locale = Astro.currentLocale! as Locale;
+const locale = (Astro.currentLocale ?? DEFAULT_LOCALE) as Locale;
const globalI18n = getIntlayer("global", locale);
---
src/utils/content.ts
@@ -38,8 +38,8 @@ export function getPostsLocaleMap(posts: CollectionEntry<"posts">[]) {
acc: Record<string, Record<string, CollectionEntry<"posts">>>,
curr: CollectionEntry<"posts">,
) => {
- const slug = curr.id.split("/").at(-1)!;
- acc[slug] = { ...acc[slug], [curr.id.split("/").at(0)!]: curr };
+ const [locale, slug] = curr.id.split("/");
+ acc[slug] = { ...acc[slug], [locale]: curr };
return acc;
},
{},
src/utils/random.ts
@@ -1,6 +1,7 @@
export function mulberry32(a: number) {
return () => {
- let t = (a += 0x6d2b79f5);
+ a += 0x6d2b79f5;
+ let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
src/content.config.ts
@@ -10,7 +10,7 @@ const typCollection = (base: string) =>
defineCollection({
loader: glob({
pattern: ["**/[^_]*.{typ,typst}", "!**/_*/**"],
- base: "./src/contents/" + base,
+ base: `./src/contents/${base}`,
generateId: ({ entry, data }) => {
const slugFromData = data.slug as string | undefined;
const filename = entry.split("/").at(-1);