Skip to content

Commit 98e3f3b

Browse files
Bissbertclaude
andcommitted
fix: prefer local enriched database over npm package in SSG
Update db-server.ts to check for local public/minerals.db first, then fall back to npm package. This ensures the enriched database with FGA-standard gemmological data is used during static site generation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 078d194 commit 98e3f3b

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/lib/db-server.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,23 @@ export async function getDB(): Promise<Database> {
4848
dbPromise = (async () => {
4949
const SQL = await initSqlJs();
5050

51-
// Try to find the database file
51+
// Prefer local database (contains enriched data) over npm package
52+
const localDbPath = join(process.cwd(), 'public', 'minerals.db');
5253
let dbPath: string;
54+
5355
try {
54-
// Try npm package first
55-
const mineralData = await import('@gemmology/mineral-data');
56-
dbPath = mineralData.dbPath;
56+
// Check if local enriched database exists
57+
readFileSync(localDbPath);
58+
dbPath = localDbPath;
5759
} catch {
58-
// Fallback to public directory
59-
dbPath = join(process.cwd(), 'public', 'minerals.db');
60+
// Fallback to npm package
61+
try {
62+
const mineralData = await import('@gemmology/mineral-data');
63+
dbPath = mineralData.dbPath;
64+
} catch {
65+
// Last resort: try src/data location
66+
dbPath = join(process.cwd(), 'src', 'data', 'minerals.db');
67+
}
6068
}
6169

6270
const buffer = readFileSync(dbPath);

0 commit comments

Comments
 (0)