From cf7e8f6026b2aa233bf19c9eefd0fb82ba4ce0b1 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Mon, 3 Aug 2026 15:34:10 -0600 Subject: [PATCH] Added refs parser and fetch. --- src/utils/modal.js | 66 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/utils/modal.js b/src/utils/modal.js index 432f196..37a1b7b 100644 --- a/src/utils/modal.js +++ b/src/utils/modal.js @@ -5,9 +5,60 @@ export const modal = (el) => { function parseRef(ref) { console.log(ref); - ref = ref.replace(/%3[Aa]/, ':'); - const m = ref.match(/((\d+\+)?[a-zA-Z]+)\+?([0-9]+)?\:([0-9]+(-?[0-9]+)?)?/); + ref = ref.replace(/%3[Aa]/, ':').replace(/\+/, ' '); + console.log(ref); + const m = ref.match(/((\d+(\+|\s))?[a-zA-Z]+)(\+|\s)?([0-9]+)?\:?([0-9]+(-?[0-9]+)?)?/); + console.log(m); + + const book = m[1]; + const chapter = m[5]; + const verses = m[6]; + + if (book === undefined) { + return {}; + } + + let refdata = { + book: _map[book], + meta: books[_map[book]] + }; + + if (chapter !== undefined) { + refdata['chapter'] = chapter; + } + + if (verses !== undefined) { + if (verses.indexOf('-') < 0) { + refdata['verse'] = verses; + } else { + refdata['verses'] = { + start: verses.substring(0, verses.indexOf('-')), + end: verses.substring(verses.indexOf('-')+1) + }; + } + } + + if ('verses' in refdata) { + if (refdata.verses.start < 1) { + refdata.verses.start = 1; + } + if (refdata.verses.start > refdata.meta.stop) { + refdata.verses.start = refdata.meta.stop; + } + if (refdata.verses.end < 1) { + refdata.verses.end = 1; + } + if (refdata.verses.end > refdata.meta.stop) { + refdata.verses.end = refdata.meta.stop; + } + if (refdata.verses.start > refdata.verses.end) { + refdata.verses.end = refdata.verses.start; + } + + } + + return refdata; } export const bindModals = () => { @@ -23,6 +74,16 @@ export const bindModals = () => { dialog[0]?.setAttribute('data-scripture', scripture); dialog[0]?.classList.remove("hidden"); //document.body.classList.add("overflow-hidden"); + + fetch('https://aries.destrealm.org/bshelton/gen1.json') + .then((response) => { + console.log(response.ok); + return response.json(); + }) + .then((response) => { + const content = response?.chapter?.content; + console.log(content); + }); }); }); dialog[0]?.addEventListener('click', (evt) => { @@ -30,7 +91,6 @@ export const bindModals = () => { }); }; - const books = { "gen": {"title": "Genesis", "start": 1, "stop": 50, "count": 50, "aliases": ["gn"],