1+ const bookManifest = [
2+ { name : "Genesis" , file : "genesis.json" } ,
3+ { name : "1 Enoch" , file : "enoch.json" }
4+ ] ;
5+
6+ let currentBookData = null ; // To store the loaded book data
7+
8+ // Fetch book data
9+ async function loadBookData ( bookFile ) {
10+ try {
11+ const response = await fetch ( `data/books/${ bookFile } ` ) ;
12+ const data = await response . json ( ) ;
13+ return data ;
14+ } catch ( error ) {
15+ console . error ( "Error loading book:" , error ) ;
16+ }
17+ }
18+
19+ // Display book list
20+ function showBooks ( ) {
21+ const bookList = document . getElementById ( 'book-list' ) ;
22+ bookList . innerHTML = bookManifest . map ( book => `
23+ <button onclick="handleBookClick('${ book . file } ')">
24+ ${ book . name }
25+ </button>
26+ ` ) . join ( '' ) ;
27+ }
28+
29+ // Handle book click
30+ async function handleBookClick ( bookFile ) {
31+ currentBookData = await loadBookData ( bookFile ) ;
32+ if ( ! currentBookData ) return ;
33+
34+ const bookName = Object . keys ( currentBookData ) [ 0 ] ; // e.g., "1 Enoch"
35+ const chapters = Object . keys ( currentBookData [ bookName ] ) ;
36+
37+ // Show chapters
38+ document . getElementById ( 'chapters-section' ) . style . display = 'block' ;
39+ document . getElementById ( 'verses-section' ) . style . display = 'none' ;
40+
41+ const chaptersDiv = document . getElementById ( 'chapters' ) ;
42+ chaptersDiv . innerHTML = chapters . map ( chapter => `
43+ <button class="chapter-btn" onclick="handleChapterClick('${ chapter } ')">
44+ Chapter ${ chapter }
45+ </button>
46+ ` ) . join ( '' ) ;
47+ }
48+
49+ // Handle chapter click
50+ function handleChapterClick ( chapter ) {
51+ const bookName = Object . keys ( currentBookData ) [ 0 ] ;
52+ const verses = currentBookData [ bookName ] [ chapter ] ;
53+
54+ document . getElementById ( 'verses-section' ) . style . display = 'block' ;
55+ const versesDiv = document . getElementById ( 'verses' ) ;
56+ versesDiv . innerHTML = Object . entries ( verses ) . map ( ( [ verse , text ] ) => `
57+ <p><b>${ verse } :</b> ${ text } </p>
58+ ` ) . join ( '' ) ;
59+ }
60+
61+ // Back buttons
62+ function showChapters ( ) {
63+ document . getElementById ( 'verses-section' ) . style . display = 'none' ;
64+ }
65+
66+ // Initialize
67+ showBooks ( ) ;
0 commit comments