- {character.messageExamples.map((conversation) => (
-
- {conversation.map((message) => (
-
-
{message.user}
-
{message.content.text}
+ {
+ character.messageExamples && character.messageExamples.length > 0 && (
+
+ Message Examples
+
+ {character.messageExamples.map((conversation) => (
+
+ {conversation.map((message) => (
+
+
{message.user}
+
{message.content.text}
+
+ ))}
))}
- ))}
-
-
+
+ )
+ }
diff --git a/src/pages/characters/[id].astro b/src/pages/characters/[id].astro
index d1c2375..2a9b84b 100644
--- a/src/pages/characters/[id].astro
+++ b/src/pages/characters/[id].astro
@@ -7,6 +7,10 @@ import type { Character } from "../../types/character";
export async function getStaticPaths() {
const characters = await getAllCharacters();
+ if (!characters || !Array.isArray(characters)) {
+ throw new Error("Failed to fetch characters data");
+ }
+
return characters.map((character) => ({
params: { id: character.id },
props: { character },
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 39f851f..8772571 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -3,7 +3,7 @@ import Layout from "../layouts/Layout.astro";
import CharacterList from "../components/CharacterList.astro";
import { getAllCharacters } from "../utils/characters";
-const characters = await getAllCharacters();
+const characters = (await getAllCharacters()).filter((char) => char != null);
---
diff --git a/src/utils/characters.ts b/src/utils/characters.ts
index 002fa26..1ad8f45 100644
--- a/src/utils/characters.ts
+++ b/src/utils/characters.ts
@@ -1,11 +1,23 @@
import type { Character } from '../types/character';
export async function getAllCharacters(): Promise {
- // Use Astro's glob imports to load all JSON files at build time
- const characterModules = await import.meta.glob('../data/characters/*.json', {
- eager: true,
- import: 'default',
- });
+ try {
+ // Use Astro's glob imports to load all JSON files at build time
+ const characterModules = await import.meta.glob('/src/data/characters/*.json', {
+ eager: true,
+ import: 'default',
+ });
- return Object.values(characterModules) as Character[];
+ if (!characterModules || Object.keys(characterModules).length === 0) {
+ console.warn('No character modules found');
+ return [];
+ }
+
+ const characters = Object.values(characterModules) as Character[];
+ console.log(`Found ${characters.length} characters`);
+ return characters;
+ } catch (error) {
+ console.error('Error loading characters:', error);
+ return [];
+ }
}