@@ -3,48 +3,6 @@ const bookManifest = [
33 { name : "1 Enoch" , file : "enoch.json" }
44] ;
55
6- let currentBook = null ;
7- const bookCache = { } ;
8-
9- // Fetch book data
10- async function loadBookData ( bookFile ) {
11- if ( ! bookCache [ bookFile ] ) {
12- const response = await fetch ( `data/books/${ bookFile } ` ) ;
13- const data = await response . json ( ) ;
14- bookCache [ bookFile ] = data ;
15- }
16- return bookCache [ bookFile ] ;
17- }
18-
19- // Load chapter 1 of a book automatically
20- async function loadBook ( bookFile ) {
21- const bookData = await loadBookData ( bookFile ) ;
22- currentBook = Object . keys ( bookData ) [ 0 ] ; // e.g., "1 Enoch"
23- const firstChapter = Object . keys ( bookData [ currentBook ] ) [ 0 ] ; // Chapter 1
24-
25- // Display verses
26- const versesDiv = document . getElementById ( 'verses' ) ;
27- versesDiv . innerHTML = `
28- <h2>${ currentBook } </h2>
29- ${ Object . entries ( bookData [ currentBook ] [ firstChapter ] )
30- . map ( ( [ verse , text ] ) => `
31- <p class="verse"><b>${ verse } :</b> ${ text } </p>
32- ` ) . join ( '' ) }
33- ` ;
34- }
35-
36- // Initialize book list
37- function initBooks ( ) {
38- const bookList = document . getElementById ( 'book-list' ) ;
39- bookList . innerHTML = bookManifest
40- . map ( book => `
41- <button onclick="loadBook('${ book . file } ')">
42- ${ book . name }
43- </button>
44- ` )
45- . join ( '' ) ;
46- }
47-
486let currentBook = null ;
497let currentChapter = null ;
508let bookData = null ;
@@ -61,6 +19,15 @@ document.getElementById('nextChapter').addEventListener('click', () => {
6119 if ( bookData [ currentBook ] [ next ] ) loadChapter ( next . toString ( ) ) ;
6220} ) ;
6321
22+ async function loadBookData ( bookFile ) {
23+ if ( ! bookCache [ bookFile ] ) {
24+ const response = await fetch ( `data/books/${ bookFile } ` ) ;
25+ const data = await response . json ( ) ;
26+ bookCache [ bookFile ] = data ;
27+ }
28+ return bookCache [ bookFile ] ;
29+ }
30+
6431async function loadBook ( bookFile ) {
6532 bookData = await loadBookData ( bookFile ) ;
6633 currentBook = Object . keys ( bookData ) [ 0 ] ;
@@ -87,18 +54,25 @@ function loadChapter(chapter) {
8754 currentChapter = chapter ;
8855 const chapterContent = bookData [ currentBook ] [ chapter ] ;
8956
90- // Update verses display
9157 document . getElementById ( 'verses' ) . innerHTML = `
9258 <h2>${ currentBook } ${ currentChapter } </h2>
9359 ${ Object . entries ( chapterContent ) . map ( ( [ verse , text ] ) => `
9460 <p><b>${ verse } :</b> ${ text } </p>
9561 ` ) . join ( '' ) }
9662 ` ;
97-
98- // Update chapter navigation
9963 updateChapterNavigation ( ) ;
10064}
10165
66+ function initBooks ( ) {
67+ const bookList = document . getElementById ( 'book-list' ) ;
68+ bookList . innerHTML = bookManifest
69+ . map ( book => `
70+ <button onclick="loadBook('${ book . file } ')">
71+ ${ book . name }
72+ </button>
73+ ` )
74+ . join ( '' ) ;
75+ }
10276
103- // Start
104- initBooks ( ) ;
77+ // Initialize the app
78+ initBooks ( ) ; // Critical missing line added
0 commit comments