switched to NKJV, improved grading, improved styling

This commit is contained in:
George Powell
2025-12-23 17:33:33 -05:00
parent 93acafc232
commit f9f0928278
16 changed files with 34345 additions and 68 deletions

View File

@@ -1,45 +1,30 @@
import type { DailyVerse } from '$lib/server/db/schema';
import { getBookById } from './bible';
import { getRandomVerses, formatReference } from './xml-bible';
type ApiVerse = Omit<DailyVerse, 'id' | 'date' | 'createdAt'>;
export async function fetchRandomVerse(): Promise<ApiVerse> {
// Step 1: Fetch random verse to get starting position
const randomRes = await fetch('https://bible-api.com/data/web/random');
if (!randomRes.ok) {
throw new Error(`Failed to fetch random verse: ${randomRes.status}`);
}
const randomData = await randomRes.json() as any;
const randomVerse = randomData.random_verse;
if (!randomVerse || !randomVerse.book_id) {
throw new Error('Invalid random verse data');
// Get 3 random verses from the local XML Bible
const verseData = getRandomVerses(3);
if (!verseData) {
throw new Error('Failed to get random verses from Bible XML');
}
const bookId = randomVerse.book_id as string;
const chapter = randomVerse.chapter as number;
const verse = randomVerse.verse as number;
const endVerse = verse + 2;
// Step 2: Fetch 3 consecutive verses starting from random
const rangeUrl = `https://bible-api.com/${bookId}${chapter}:${verse}-${endVerse}`;
const rangeRes = await fetch(rangeUrl);
if (!rangeRes.ok) {
throw new Error(`Failed to fetch verse range: ${rangeRes.status}`);
}
const rangeData = await rangeRes.json() as any;
const reference = rangeData.reference as string;
const verses = rangeData.verses as any[];
if (!verses || verses.length === 0) {
throw new Error('No verses in range');
}
const verseText = verses.map((v: any) => v.text).join(' ');
const { bookId, bookName, chapter, startVerse, endVerse, verses } = verseData;
// Validate bookId
if (!getBookById(bookId)) {
throw new Error(`Unknown book ID from API: ${bookId}`);
throw new Error(`Unknown book ID: ${bookId}`);
}
// Format the reference string (e.g., "Matthew 1:1-3")
const reference = formatReference(bookName, chapter, startVerse, endVerse);
// Join verses with spaces
const verseText = verses.join(' ');
return {
bookId,
reference,