1+ const bookManifest = [
2+ { name : "Genesis" , file : "genesis.json" } ,
3+ { name : "1 Enoch" , file : "enoch.json" }
4+ ] ;
5+
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+
148let currentBook = null ;
249let currentChapter = null ;
350let bookData = null ;
@@ -52,5 +99,6 @@ function loadChapter(chapter) {
5299 updateChapterNavigation ( ) ;
53100}
54101
55- // Rest of the script remains the same until the init function
56- // (Previous loadBookData and initBooks functions stay unchanged)
102+
103+ // Start
104+ initBooks ( ) ;
0 commit comments