feat: allow path params for verse navigation
This commit is contained in:
+85
-6
@@ -30,7 +30,7 @@ if (!DATABASE_URL) {
|
||||
}
|
||||
|
||||
const BASE_DIR = path.resolve(__dirname, "..");
|
||||
const LIB_DIR = path.join(BASE_DIR, "app", "lib");
|
||||
const LIB_DIR = path.join(BASE_DIR, "lib", "jsons");
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
@@ -95,6 +95,18 @@ type CcVerse = {
|
||||
purport: string[];
|
||||
};
|
||||
|
||||
type Sb1962Verse = {
|
||||
book_title: string;
|
||||
chapter: number;
|
||||
verse: number;
|
||||
verse_end?: number;
|
||||
reference: string;
|
||||
transliteration: string;
|
||||
synonyms: { word: string; meanings: string[] }[];
|
||||
translation: string;
|
||||
purport: string[];
|
||||
};
|
||||
|
||||
type GlossaryData = {
|
||||
title: string;
|
||||
description: string;
|
||||
@@ -328,6 +340,69 @@ async function seedCc(db: ReturnType<MongoClient["db"]>) {
|
||||
console.log(` ✅ CC: ${totalCount} verses`);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SB 1962
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function seedSb1962(db: ReturnType<MongoClient["db"]>) {
|
||||
const introPath = path.join(LIB_DIR, "books", "sb-1962", "intro.json");
|
||||
if (!fs.existsSync(introPath)) {
|
||||
console.log(" ⏭ SB 1962 intro.json not found, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
const intro = readJson(introPath);
|
||||
|
||||
const metaCol = db.collection("book_meta");
|
||||
await metaCol.deleteMany({ book: "sb1962" });
|
||||
await metaCol.insertOne({ book: "sb1962", data: intro });
|
||||
console.log(" 📖 SB 1962 book meta inserted");
|
||||
|
||||
const versesCol = db.collection("verses");
|
||||
await versesCol.deleteMany({ book: "sb1962" });
|
||||
|
||||
const chaptersDir = path.join(LIB_DIR, "books", "sb-1962", "chapters");
|
||||
if (!fs.existsSync(chaptersDir)) {
|
||||
console.log(" ⏭ SB 1962 chapters dir not found, skipping verses");
|
||||
return;
|
||||
}
|
||||
|
||||
const chapterDirs = fs
|
||||
.readdirSync(chaptersDir)
|
||||
.filter((d) => fs.statSync(path.join(chaptersDir, d)).isDirectory())
|
||||
.sort();
|
||||
|
||||
const docs: Record<string, unknown>[] = [];
|
||||
|
||||
for (const chDir of chapterDirs) {
|
||||
const versesDir = path.join(chaptersDir, chDir, "verses");
|
||||
const verses = readAllJsonInDir(versesDir) as Sb1962Verse[];
|
||||
|
||||
for (const v of verses) {
|
||||
docs.push({
|
||||
book: "sb1962",
|
||||
division: null,
|
||||
chapter: v.chapter,
|
||||
verse: v.verse,
|
||||
verseEnd: v.verse_end ?? null,
|
||||
reference: v.reference,
|
||||
bookTitle: v.book_title,
|
||||
devanagari: "",
|
||||
bengali: null,
|
||||
transliteration: v.transliteration,
|
||||
synonyms: v.synonyms,
|
||||
translation: v.translation,
|
||||
purport: v.purport,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (docs.length > 0) {
|
||||
await versesCol.insertMany(docs, { ordered: false });
|
||||
}
|
||||
console.log(` ✅ SB 1962: ${docs.length} verses`);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Glossary
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -396,23 +471,27 @@ async function main() {
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
console.log("[1/5] Bhagavad-gītā");
|
||||
console.log("[1/6] Bhagavad-gītā");
|
||||
await seedBg(db);
|
||||
console.log();
|
||||
|
||||
console.log("[2/5] Śrīmad-Bhāgavatam");
|
||||
console.log("[2/6] Śrīmad-Bhāgavatam");
|
||||
await seedSb(db);
|
||||
console.log();
|
||||
|
||||
console.log("[3/5] Śrī Caitanya-caritāmṛta");
|
||||
console.log("[3/6] Śrī Caitanya-caritāmṛta");
|
||||
await seedCc(db);
|
||||
console.log();
|
||||
|
||||
console.log("[4/5] Glossary");
|
||||
console.log("[4/6] Śrīmad-Bhāgavatam (1962 Edition)");
|
||||
await seedSb1962(db);
|
||||
console.log();
|
||||
|
||||
console.log("[5/6] Glossary");
|
||||
await seedGlossary(db);
|
||||
console.log();
|
||||
|
||||
console.log("[5/5] Indexes");
|
||||
console.log("[6/6] Indexes");
|
||||
await createIndexes(db);
|
||||
console.log();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user