WIP fixes, mostly working, but display bugs are present.
As of now, if there is an inline footnote, it will cause a paragraph break because of the way the JSON processor currently handles "poem" declarations. The only solution for this may be to rework the loop so some lookahead is possible.
This commit is contained in:
parent
661dbef6f9
commit
272740effe
3 changed files with 37 additions and 28 deletions
|
|
@ -13,13 +13,18 @@ function parseRef(ref) {
|
|||
|
||||
const book = m[1];
|
||||
const chapter = m[5];
|
||||
const verses = m[6];
|
||||
const verses = m[6]?.replaceAll(/–/g, '-');
|
||||
|
||||
console.log(`parseRef: ${book}, ${chapter}, ${verses}`);
|
||||
console.log(books);
|
||||
|
||||
if (book === undefined) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let refdata = {};
|
||||
let refdata = {
|
||||
ref: ref
|
||||
};
|
||||
if (book in books) {
|
||||
refdata.book = book;
|
||||
} else if (book in _map) {
|
||||
|
|
@ -36,13 +41,13 @@ function parseRef(ref) {
|
|||
if (verses !== undefined) {
|
||||
if (verses.indexOf('-') < 0) {
|
||||
refdata['verses'] = {
|
||||
start: verses,
|
||||
end: verses
|
||||
start: parseInt(verses),
|
||||
end: parseInt(verses)
|
||||
};
|
||||
} else {
|
||||
refdata['verses'] = {
|
||||
start: verses.substring(0, verses.indexOf('-')),
|
||||
end: verses.substring(verses.indexOf('-')+1)
|
||||
start: parseInt(verses.substring(0, verses.indexOf('-'))),
|
||||
end: parseInt(verses.substring(verses.indexOf('-')+1))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -52,15 +57,9 @@ function parseRef(ref) {
|
|||
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;
|
||||
}
|
||||
|
|
@ -69,18 +68,21 @@ function parseRef(ref) {
|
|||
return refdata;
|
||||
}
|
||||
|
||||
function render(dialog, response) {
|
||||
function render(dialog, response, refs) {
|
||||
const content = response?.chapter?.content;
|
||||
const refs = parseRef('gen+1:4');
|
||||
let inSpan = false;
|
||||
|
||||
if (dialog === null || dialog === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('render refs:', refs);
|
||||
|
||||
const section = document.createElement('section');
|
||||
let para = document.createElement('p');
|
||||
|
||||
dialog.querySelector('a.bg').href = `https://www.biblegateway.com/passage/?search=${refs.ref}&version=ESV`
|
||||
|
||||
for (const c of content) {
|
||||
if (c.type === 'heading') {
|
||||
continue;
|
||||
|
|
@ -137,9 +139,9 @@ function render(dialog, response) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
console.log('unhandled type:', c.type);
|
||||
console.error('unhandled type:', c.type);
|
||||
}
|
||||
console.log(c);
|
||||
//console.log(c);
|
||||
}
|
||||
section.insertAdjacentElement('beforeend', para);
|
||||
dialog?.querySelector('article').insertAdjacentElement('beforeend', section);
|
||||
|
|
@ -152,32 +154,36 @@ export const bindModals = () => {
|
|||
elems.forEach((e) => {
|
||||
e.addEventListener('click', (evt) => {
|
||||
const scripture = e.attributes.getNamedItem('data-scripture');
|
||||
const refs = parseRef(scripture.value);
|
||||
evt.preventDefault();
|
||||
console.log(scripture);
|
||||
console.log(parseRef(scripture.value));
|
||||
console.log('scripture:', scripture);
|
||||
console.log('refs:', refs);
|
||||
const uri = `https://bible.helloao.org/api/BSB/${refs.book.toUpperCase()}/${refs.chapter}.json`;
|
||||
dialog[0]?.showModal();
|
||||
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')
|
||||
fetch(uri)
|
||||
.then((response) => {
|
||||
console.log(response.ok);
|
||||
return response.json();
|
||||
})
|
||||
.then((response) => {
|
||||
render(dialog[0], response);
|
||||
render(dialog[0], response, refs);
|
||||
});
|
||||
});
|
||||
});
|
||||
dialog[0]?.addEventListener('click', (evt) => {
|
||||
evt.target === dialog[0] && dialog[0]?.close();
|
||||
dialog[0]?.querySelector('article')?.replaceChildren();
|
||||
|
||||
if (evt.target === dialog[0]) {
|
||||
dialog[0]?.close();
|
||||
dialog[0]?.querySelector('article')?.replaceChildren();
|
||||
}
|
||||
});
|
||||
dialog[0]?.querySelector('button[data-close]')?.addEventListener('click', (evt) => {
|
||||
evt.preventDefault();
|
||||
dialog[0]?.close();
|
||||
dialog[0]?.classList.add('hidden');
|
||||
dialog[0]?.querySelector('article')?.replaceChildren();
|
||||
});
|
||||
};
|
||||
|
|
@ -240,7 +246,7 @@ const books = {
|
|||
"aliases": ["jo"],
|
||||
},
|
||||
"psa": {"title": "Psalms", "start": 1, "stop": 150, "count": 150,
|
||||
"aliases": ["ps", "pss"],
|
||||
"aliases": ["ps", "psalm", "pss"],
|
||||
},
|
||||
"pro": {"title": "Proverbs", "start": 1, "stop": 31, "count": 31,
|
||||
"aliases": ["pr", "prov"],
|
||||
|
|
|
|||
Loading…
Reference in a new issue