Added greek bible and centered title correctly and added date

This commit is contained in:
George Powell
2025-12-23 22:56:46 -05:00
parent f9f0928278
commit 0e3505b8e7
8 changed files with 33887 additions and 14 deletions

View File

@@ -29,7 +29,7 @@
</script>
<div
class="title-container relative inline-block cursor-pointer"
class="title-container relative flex justify-center cursor-pointer"
onmouseenter={handleMouseEnter}
onmouseleave={handleMouseLeave}
onclick={handleTap}
@@ -48,7 +48,7 @@
<!-- BIBLE DAILY (expanded state) -->
<div
class="title-expanded flex flex-row items-center justify-center transition-all duration-500 ease-in-out"
class="title-expanded absolute inset-0 items-center justify-center transition-all duration-500 ease-in-out"
class:opacity-0={!showExpanded}
class:opacity-100={showExpanded}
>
@@ -68,6 +68,7 @@
<style>
.title-container {
min-height: 1.5em;
width: 100%;
}
.title-word,
@@ -75,6 +76,7 @@
font-weight: bold;
text-transform: uppercase;
letter-spacing: 0.2em;
margin-right: -0.3em; /* Compensate for letter-spacing to center properly */
}
.title-expanded span {

View File

@@ -15,6 +15,7 @@ const parser = new XMLParser({
// Cache for parsed Bible data to avoid re-reading the file
let cachedBible: any = null;
let cachedGreekBible: any = null;
interface VerseData {
number: number;
@@ -56,6 +57,19 @@ function loadBibleXml(): BibleData {
return cachedBible;
}
/**
* Load and parse the Greek Bible XML file
*/
function loadGreekBibleXml(): BibleData {
if (cachedGreekBible) {
return cachedGreekBible;
}
const xmlPath = join(process.cwd(), 'GreekModern1904Bible.xml');
const xmlContent = readFileSync(xmlPath, 'utf-8');
cachedGreekBible = parser.parse(xmlContent) as BibleData;
return cachedGreekBible;
}
/**
* Get a specific book from the Bible XML
*/
@@ -75,6 +89,25 @@ function getBook(bookNumber: number): BookData | null {
return testament.book[bookIndex] || null;
}
/**
* Get a specific book from the Greek Bible XML
*/
function getGreekBook(bookNumber: number): BookData | null {
const bible = loadGreekBibleXml();
// Old Testament books are 1-39, New Testament are 40-66
const testamentIndex = bookNumber <= 39 ? 0 : 1;
const testament = bible.bible.testament[testamentIndex];
if (!testament) {
return null;
}
// Find the book by number within the testament
const bookIndex = bookNumber <= 39 ? bookNumber - 1 : bookNumber - 40;
return testament.book[bookIndex] || null;
}
/**
* Get a specific chapter from a book
*/
@@ -87,6 +120,18 @@ function getChapter(bookNumber: number, chapterNumber: number): ChapterData | nu
return book.chapter.find((ch) => ch.number === chapterNumber) || null;
}
/**
* Get a specific chapter from the Greek Bible
*/
function getGreekChapter(bookNumber: number, chapterNumber: number): ChapterData | null {
const book = getGreekBook(bookNumber);
if (!book) {
return null;
}
return book.chapter.find((ch) => ch.number === chapterNumber) || null;
}
/**
* Get the number of verses in a specific chapter
*/
@@ -95,6 +140,14 @@ function getVerseCount(bookNumber: number, chapterNumber: number): number {
return chapter ? chapter.verse.length : 0;
}
/**
* Get the number of verses in a specific Greek chapter
*/
function getGreekVerseCount(bookNumber: number, chapterNumber: number): number {
const chapter = getGreekChapter(bookNumber, chapterNumber);
return chapter ? chapter.verse.length : 0;
}
/**
* Get the number of chapters in a specific book
*/
@@ -103,10 +156,18 @@ function getChapterCount(bookNumber: number): number {
return book ? book.chapter.length : 0;
}
/**
* Get the number of chapters in a specific Greek book
*/
function getGreekChapterCount(bookNumber: number): number {
const book = getGreekBook(bookNumber);
return book ? book.chapter.length : 0;
}
/**
* Extract consecutive verses from a specific location
*/
function extractVerses(
export function extractVerses(
bookNumber: number,
chapterNumber: number,
startVerse: number,
@@ -129,6 +190,32 @@ function extractVerses(
return verses;
}
/**
* Extract consecutive verses from a specific Greek location
*/
function extractGreekVerses(
bookNumber: number,
chapterNumber: number,
startVerse: number,
count: number
): string[] {
const chapter = getGreekChapter(bookNumber, chapterNumber);
if (!chapter) {
return [];
}
const verses: string[] = [];
for (let i = 0; i < count; i++) {
const verseIndex = startVerse - 1 + i; // Convert to 0-based index
if (verseIndex >= chapter.verse.length) {
break;
}
verses.push(chapter.verse[verseIndex]._text);
}
return verses;
}
/**
* Get a random book number (1-66)
*/
@@ -154,6 +241,24 @@ function getRandomStartVerse(bookNumber: number, chapterNumber: number, verseCou
return Math.floor(Math.random() * maxStartVerse) + 1;
}
/**
* Get a random chapter number for a specific Greek book
*/
function getRandomGreekChapterNumber(bookNumber: number): number {
const chapterCount = getGreekChapterCount(bookNumber);
return Math.floor(Math.random() * chapterCount) + 1;
}
/**
* Get a random starting verse number for a specific Greek chapter
* Ensures there are enough verses for the requested count
*/
function getRandomGreekStartVerse(bookNumber: number, chapterNumber: number, verseCount: number): number {
const totalVerses = getGreekVerseCount(bookNumber, chapterNumber);
const maxStartVerse = Math.max(1, totalVerses - verseCount + 1);
return Math.floor(Math.random() * maxStartVerse) + 1;
}
/**
* Get a random set of verses from the Bible
* Returns 3 consecutive verses by default
@@ -201,6 +306,53 @@ export function getRandomVerses(count: number = 3): {
return null;
}
/**
* Get a random set of verses from the Greek Bible
* Returns 3 consecutive verses by default
*/
export function getRandomGreekVerses(count: number = 3): {
bookId: string;
bookName: string;
chapter: number;
startVerse: number;
endVerse: number;
verses: string[];
} | null {
// Try up to 10 times to find a valid passage
for (let attempt = 0; attempt < 10; attempt++) {
const bookNumber = getRandomBookNumber();
const book = getBookByNumber(bookNumber);
if (!book) {
continue;
}
const chapterNumber = getRandomGreekChapterNumber(bookNumber);
const verseCount = getGreekVerseCount(bookNumber, chapterNumber);
// Skip chapters that don't have enough verses
if (verseCount < count) {
continue;
}
const startVerse = getRandomGreekStartVerse(bookNumber, chapterNumber, count);
const verses = extractGreekVerses(bookNumber, chapterNumber, startVerse, count);
if (verses.length === count) {
return {
bookId: book.id,
bookName: book.name,
chapter: chapterNumber,
startVerse,
endVerse: startVerse + count - 1,
verses
};
}
}
return null;
}
/**
* Format a reference string from verse data
*/

View File

@@ -43,6 +43,15 @@
let guessedIds = $derived(new Set(guesses.map((g) => g.book.id)));
const currentDate = $derived(
new Date().toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
})
);
let isWon = $derived(guesses.some((g) => g.book.id === correctBookId));
let grade = $derived(
isWon
@@ -356,18 +365,21 @@
<title>Bibdle &mdash; A daily bible game{isDev ? " (dev)" : ""}</title>
<meta
name="description"
content="Guess which book of the Bible a daily verse comes from. A Wordle-inspired Bible game!"
content="A Wordle-inspired Bible game (short for Bible Daily)"
/>
</svelte:head>
<div class="min-h-dvh md:bg-linear-to-br md:from-blue-50 md:to-indigo-200 py-8">
<div class="w-full max-w-3xl mx-auto px-4">
<h1
class="text-3xl md:text-4xl font-bold text-center uppercase text-gray-600 drop-shadow-2xl tracking-widest p-8 sm:p-12"
class="text-3xl md:text-4xl font-bold text-center uppercase text-gray-600 drop-shadow-2xl tracking-widest p-4 sm:p-8"
>
<TitleAnimation />
<span class="font-normal">{isDev ? "dev" : ""}</span>
<div class="font-normal">{false ? "dev" : ""}</div>
</h1>
<div class="text-center mb-8">
<span class="big-text">{currentDate}</span>
</div>
<VerseDisplay {data} {isWon} />

View File

@@ -0,0 +1,37 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { getRandomGreekVerses, extractVerses, formatReference } from '$lib/server/xml-bible';
import { getBookById, bookIdToNumber } from '$lib/server/bible';
export const load: PageServerLoad = async () => {
const greekData = getRandomGreekVerses(3);
if (!greekData) {
throw error(500, 'Failed to load Greek verses');
}
const bookNumber = bookIdToNumber[greekData.bookId];
const englishVerses = extractVerses(bookNumber, greekData.chapter, greekData.startVerse, 3);
const reference = formatReference(greekData.bookName, greekData.chapter, greekData.startVerse, greekData.endVerse);
const greekVerseText = greekData.verses.join(' ');
const englishVerseText = englishVerses.join(' ');
const dailyVerse = {
id: 'greek-random-' + Date.now(),
date: new Date().toLocaleDateString('en-CA', { timeZone: 'America/New_York' }),
bookId: greekData.bookId,
reference,
verseText: englishVerseText,
createdAt: new Date()
};
const correctBook = getBookById(dailyVerse.bookId) ?? null;
return {
dailyVerse,
greekVerseText,
reference,
correctBookId: dailyVerse.bookId,
correctBook
};
};

View File

@@ -0,0 +1,46 @@
<script lang="ts">
import type { PageProps } from "./$types";
import VerseDisplay from "$lib/components/VerseDisplay.svelte";
let { data }: PageProps = $props();
let dailyVerse = $derived(data.dailyVerse);
let greekVerseText = $derived(data.greekVerseText ?? "");
let reference = $derived(data.reference ?? "");
</script>
<svelte:head>
<title>Greek/English Random Verse - Bibdle</title>
</svelte:head>
<div class="min-h-screen bg-linear-to-br from-blue-50 to-indigo-100 py-12 px-4">
<div class="max-w-4xl mx-auto">
<h1 class="text-4xl font-bold text-center text-gray-800 mb-8">
Greek/English Parallel Random Verse
</h1>
<div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
<h2 class="text-xl font-semibold text-gray-700 mb-4">
Greek Verse (Modern 1904)
</h2>
<div class="space-y-2 text-gray-600 text-lg leading-relaxed">
<p><strong>Reference:</strong> {reference}</p>
<p><strong>Greek:</strong> {greekVerseText}</p>
</div>
</div>
<div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
<h2 class="text-xl font-semibold text-gray-700 mb-4">
English Equivalent (NKJV)
</h2>
<div class="space-y-2 text-gray-600">
<p><strong>Book ID:</strong> {dailyVerse.bookId}</p>
<p><strong>Reference:</strong> {dailyVerse.reference}</p>
<p><strong>Verse Text:</strong> {dailyVerse.verseText}</p>
</div>
</div>
<VerseDisplay {data} isWon={true} />
</div>
</div>