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
|
|
@ -73,7 +73,7 @@ const meta = `{
|
||||||
<article class="mt-6">
|
<article class="mt-6">
|
||||||
</article>
|
</article>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="#">
|
<a href="#" class="bg">
|
||||||
Open on Bible Gateway
|
Open on Bible Gateway
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link inline" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link inline" viewBox="0 0 16 16">
|
||||||
<path d="M6.354 5.5H4a3 3 0 0 0 0 6h3a3 3 0 0 0 2.83-4H9q-.13 0-.25.031A2 2 0 0 1 7 10.5H4a2 2 0 1 1 0-4h1.535c.218-.376.495-.714.82-1z"/>
|
<path d="M6.354 5.5H4a3 3 0 0 0 0 6h3a3 3 0 0 0 2.83-4H9q-.13 0-.25.031A2 2 0 0 1 7 10.5H4a2 2 0 1 1 0-4h1.535c.218-.376.495-.714.82-1z"/>
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,11 @@ dialog.scripture {
|
||||||
p.poem-1, p.poem-2 {
|
p.poem-1, p.poem-2 {
|
||||||
@apply mb-0;
|
@apply mb-0;
|
||||||
}
|
}
|
||||||
|
p.poem-1 {
|
||||||
|
@apply pl-6;
|
||||||
|
}
|
||||||
p.poem-2 {
|
p.poem-2 {
|
||||||
@apply mt-0;
|
@apply mt-0 pl-14;
|
||||||
}
|
}
|
||||||
button[data-close] {
|
button[data-close] {
|
||||||
@apply absolute top-0 right-0 pr-2 pb-2 pt-2 text-sm text-gray-500 cursor-pointer hover:text-red-900;
|
@apply absolute top-0 right-0 pr-2 pb-2 pt-2 text-sm text-gray-500 cursor-pointer hover:text-red-900;
|
||||||
|
|
@ -151,7 +154,7 @@ dialog.scripture {
|
||||||
nav {
|
nav {
|
||||||
@apply mt-8;
|
@apply mt-8;
|
||||||
a {
|
a {
|
||||||
@apply absolute bottom-0 right-0 text-sm text-blue-400 pr-4 pb-4;
|
@apply bottom-0 right-0 text-sm text-blue-400 pr-4 pb-4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,18 @@ function parseRef(ref) {
|
||||||
|
|
||||||
const book = m[1];
|
const book = m[1];
|
||||||
const chapter = m[5];
|
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) {
|
if (book === undefined) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
let refdata = {};
|
let refdata = {
|
||||||
|
ref: ref
|
||||||
|
};
|
||||||
if (book in books) {
|
if (book in books) {
|
||||||
refdata.book = book;
|
refdata.book = book;
|
||||||
} else if (book in _map) {
|
} else if (book in _map) {
|
||||||
|
|
@ -36,13 +41,13 @@ function parseRef(ref) {
|
||||||
if (verses !== undefined) {
|
if (verses !== undefined) {
|
||||||
if (verses.indexOf('-') < 0) {
|
if (verses.indexOf('-') < 0) {
|
||||||
refdata['verses'] = {
|
refdata['verses'] = {
|
||||||
start: verses,
|
start: parseInt(verses),
|
||||||
end: verses
|
end: parseInt(verses)
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
refdata['verses'] = {
|
refdata['verses'] = {
|
||||||
start: verses.substring(0, verses.indexOf('-')),
|
start: parseInt(verses.substring(0, verses.indexOf('-'))),
|
||||||
end: verses.substring(verses.indexOf('-')+1)
|
end: parseInt(verses.substring(verses.indexOf('-')+1))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,15 +57,9 @@ function parseRef(ref) {
|
||||||
if (refdata.verses.start < 1) {
|
if (refdata.verses.start < 1) {
|
||||||
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) {
|
if (refdata.verses.end < 1) {
|
||||||
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) {
|
if (refdata.verses.start > refdata.verses.end) {
|
||||||
refdata.verses.end = refdata.verses.start;
|
refdata.verses.end = refdata.verses.start;
|
||||||
}
|
}
|
||||||
|
|
@ -69,18 +68,21 @@ function parseRef(ref) {
|
||||||
return refdata;
|
return refdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(dialog, response) {
|
function render(dialog, response, refs) {
|
||||||
const content = response?.chapter?.content;
|
const content = response?.chapter?.content;
|
||||||
const refs = parseRef('gen+1:4');
|
|
||||||
let inSpan = false;
|
let inSpan = false;
|
||||||
|
|
||||||
if (dialog === null || dialog === undefined) {
|
if (dialog === null || dialog === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('render refs:', refs);
|
||||||
|
|
||||||
const section = document.createElement('section');
|
const section = document.createElement('section');
|
||||||
let para = document.createElement('p');
|
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) {
|
for (const c of content) {
|
||||||
if (c.type === 'heading') {
|
if (c.type === 'heading') {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -137,9 +139,9 @@ function render(dialog, response) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('unhandled type:', c.type);
|
console.error('unhandled type:', c.type);
|
||||||
}
|
}
|
||||||
console.log(c);
|
//console.log(c);
|
||||||
}
|
}
|
||||||
section.insertAdjacentElement('beforeend', para);
|
section.insertAdjacentElement('beforeend', para);
|
||||||
dialog?.querySelector('article').insertAdjacentElement('beforeend', section);
|
dialog?.querySelector('article').insertAdjacentElement('beforeend', section);
|
||||||
|
|
@ -152,32 +154,36 @@ export const bindModals = () => {
|
||||||
elems.forEach((e) => {
|
elems.forEach((e) => {
|
||||||
e.addEventListener('click', (evt) => {
|
e.addEventListener('click', (evt) => {
|
||||||
const scripture = e.attributes.getNamedItem('data-scripture');
|
const scripture = e.attributes.getNamedItem('data-scripture');
|
||||||
|
const refs = parseRef(scripture.value);
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
console.log(scripture);
|
console.log('scripture:', scripture);
|
||||||
console.log(parseRef(scripture.value));
|
console.log('refs:', refs);
|
||||||
|
const uri = `https://bible.helloao.org/api/BSB/${refs.book.toUpperCase()}/${refs.chapter}.json`;
|
||||||
dialog[0]?.showModal();
|
dialog[0]?.showModal();
|
||||||
dialog[0]?.setAttribute('data-scripture', scripture);
|
dialog[0]?.setAttribute('data-scripture', scripture);
|
||||||
dialog[0]?.classList.remove("hidden");
|
dialog[0]?.classList.remove("hidden");
|
||||||
//document.body.classList.add("overflow-hidden");
|
//document.body.classList.add("overflow-hidden");
|
||||||
|
|
||||||
fetch('https://aries.destrealm.org/bshelton/gen1.json')
|
fetch(uri)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response.ok);
|
console.log(response.ok);
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
render(dialog[0], response);
|
render(dialog[0], response, refs);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
dialog[0]?.addEventListener('click', (evt) => {
|
dialog[0]?.addEventListener('click', (evt) => {
|
||||||
evt.target === dialog[0] && dialog[0]?.close();
|
if (evt.target === dialog[0]) {
|
||||||
dialog[0]?.querySelector('article')?.replaceChildren();
|
dialog[0]?.close();
|
||||||
|
dialog[0]?.querySelector('article')?.replaceChildren();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialog[0]?.querySelector('button[data-close]')?.addEventListener('click', (evt) => {
|
dialog[0]?.querySelector('button[data-close]')?.addEventListener('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
dialog[0]?.close();
|
dialog[0]?.close();
|
||||||
|
dialog[0]?.classList.add('hidden');
|
||||||
dialog[0]?.querySelector('article')?.replaceChildren();
|
dialog[0]?.querySelector('article')?.replaceChildren();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -240,7 +246,7 @@ const books = {
|
||||||
"aliases": ["jo"],
|
"aliases": ["jo"],
|
||||||
},
|
},
|
||||||
"psa": {"title": "Psalms", "start": 1, "stop": 150, "count": 150,
|
"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,
|
"pro": {"title": "Proverbs", "start": 1, "stop": 31, "count": 31,
|
||||||
"aliases": ["pr", "prov"],
|
"aliases": ["pr", "prov"],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue