Read entire bible
This commit is contained in:
+9
-33
@@ -1,31 +1,9 @@
|
||||
export interface KJVVerseData {
|
||||
verse: number
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface KJVChapterData {
|
||||
chapter: string
|
||||
verses: KJVVerseData[]
|
||||
}
|
||||
|
||||
export interface KJVBookData {
|
||||
book: string
|
||||
chapters: KJVChapterData[]
|
||||
}
|
||||
|
||||
export interface KJVData {
|
||||
books: KJVBookData[]
|
||||
}
|
||||
|
||||
export interface Verse {
|
||||
text: string
|
||||
reference: string
|
||||
}
|
||||
|
||||
let flat: Verse[] | null = null
|
||||
import { getBooks, loadBible, type Verse } from './bible'
|
||||
|
||||
const ROLLOVER_LOCAL_HOUR = 2
|
||||
|
||||
let flatNT: Verse[] | null = null
|
||||
|
||||
export function daySeed(now: Date = new Date()): number {
|
||||
const shifted = new Date(now.getTime() - ROLLOVER_LOCAL_HOUR * 3600_000)
|
||||
return Math.floor(Date.UTC(shifted.getFullYear(), shifted.getMonth(), shifted.getDate()) / 86_400_000)
|
||||
@@ -55,22 +33,20 @@ export function pickForDay(verses: Verse[], seed: number): Verse {
|
||||
}
|
||||
|
||||
export async function loadKJV(): Promise<Verse[]> {
|
||||
if (flat) return flat
|
||||
const res = await fetch('/kjv.json')
|
||||
if (!res.ok) throw new Error(`Failed to load scripture (${res.status})`)
|
||||
const data = (await res.json()) as KJVData
|
||||
flat = []
|
||||
if (flatNT) return flatNT
|
||||
await loadBible()
|
||||
flatNT = []
|
||||
let inNewTestament = false
|
||||
for (const book of data.books) {
|
||||
for (const book of getBooks()) {
|
||||
if (book.book === 'Matthew') inNewTestament = true
|
||||
if (!inNewTestament) continue
|
||||
const name = book.book === 'Psalms' ? 'Psalm' : book.book
|
||||
for (const chapter of book.chapters) {
|
||||
const chapterNumber = Number(chapter.chapter)
|
||||
for (const v of chapter.verses) {
|
||||
flat.push({ text: v.text, reference: `${name} ${chapterNumber}:${v.verse}` })
|
||||
flatNT.push({ text: v.text, reference: `${name} ${chapterNumber}:${v.verse}` })
|
||||
}
|
||||
}
|
||||
}
|
||||
return flat
|
||||
return flatNT
|
||||
}
|
||||
Reference in New Issue
Block a user