Added Refs class for processing chapter/verse numbers with the extension
of possible filters for special-case handling.
This commit is contained in:
parent
25a56f2ede
commit
55d9f2d482
1 changed files with 107 additions and 5 deletions
|
|
@ -1,17 +1,117 @@
|
||||||
import { aliases, defaulttx, meta, translations } from './meta.js';
|
import { aliases, defaulttx, meta, translations } from './meta.js';
|
||||||
import { hasLocalStorage } from './utils.js';
|
import { hasLocalStorage } from './utils.js';
|
||||||
|
|
||||||
export const modal = (el) => {
|
const bookTransforms = {
|
||||||
|
'oba': {
|
||||||
|
chapter: (ref) => {
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
verse: (ref) => {
|
||||||
|
return ref.getChapter();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'jud': {
|
||||||
|
chapter: (ref) => {
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
verse: (ref) => {
|
||||||
|
return ref.getChapter();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'psa': {
|
||||||
|
match: {
|
||||||
|
ts: 'LXX',
|
||||||
|
},
|
||||||
|
chapter: (ref) => {
|
||||||
|
return 999;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Refs {
|
||||||
|
constructor(book, chapter, verse, ts) {
|
||||||
|
this._book = aliases[book.toLowerCase()];
|
||||||
|
this._chapter = chapter;
|
||||||
|
this._verse = verse;
|
||||||
|
this._ts = ['OT', 'NT'];
|
||||||
|
if (ts !== undefined) {
|
||||||
|
this._ts = ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fullTitle() {
|
||||||
|
let title = refdata.meta.title+' ';
|
||||||
|
title += refdata.chapter;
|
||||||
|
|
||||||
|
if (refdata.verses?.start > 0) {
|
||||||
|
title += ':'+refdata.verses.start;
|
||||||
|
}
|
||||||
|
if (refdata.verses?.end > 0 && refdata.verses?.end > refdata.verses?.start) {
|
||||||
|
title += '-'+refdata.verses.end;
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
getChapter() {
|
||||||
|
if (typeof(this._chapter) === 'number' || (typeof(this._chapter) === 'string' && this._chapter.indexOf('-') == -1)) {
|
||||||
|
return parseInt(this._chapter);
|
||||||
|
}
|
||||||
|
return [parseInt(this._chapter.substr(0, this._chapter.indexOf('-'))),
|
||||||
|
parseInt(this._chapter.substr(this._chapter.indexOf('-')+1))];
|
||||||
|
}
|
||||||
|
get chapter() {
|
||||||
|
if (this._book in bookTransforms) {
|
||||||
|
const bt = bookTransforms[this._book];
|
||||||
|
if ('match' in bt) {
|
||||||
|
if ('ts' in bt.match && this._ts.indexOf(bt.match.ts) == -1) {
|
||||||
|
console.log('not matched');
|
||||||
|
return this.getChapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const tx = bt;
|
||||||
|
if ('chapter' in tx) {
|
||||||
|
return tx['chapter'](this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.getChapter();
|
||||||
|
}
|
||||||
|
getVerse() {
|
||||||
|
if (typeof(this._verse) === 'number' || (typeof(this._verse) === 'string' && this._verse.indexOf('-') == -1)) {
|
||||||
|
return parseInt(this._verse);
|
||||||
|
}
|
||||||
|
if (typeof(this._verse) === 'string' && this._verse.endsWidth('ff')) {
|
||||||
|
return [parseInt(this._verse.substr(0, this._verse.length-2)), 'ff'];
|
||||||
|
}
|
||||||
|
return [parseInt(this._verse.substr(0, this._verse.indexOf('-'))),
|
||||||
|
parseInt(this._verse.substr(this._verse.indexOf('-')+1))];
|
||||||
|
}
|
||||||
|
get verse() {
|
||||||
|
if (this._book in bookTransforms) {
|
||||||
|
const tx = bookTransforms[this._book];
|
||||||
|
if ('verse' in tx) {
|
||||||
|
return tx['verse'](this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.getVerse();
|
||||||
|
}
|
||||||
|
get meta() {
|
||||||
|
if (this._book in meta) {
|
||||||
|
return meta[this.book];
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseRef(ref) {
|
function parseRef(ref) {
|
||||||
ref = ref.replace(/%3[Aa]/, ':').replace(/\+/, ' ');
|
ref = ref
|
||||||
const m = ref.match(/((\d+(\+|\s))?[a-zA-Z]+)(\+|\s)?([0-9]+)?\:?([0-9]+(-?[0-9]+)?)?/);
|
// Limited URL decoding.
|
||||||
|
.replace(/%3[Aa]/, ':')
|
||||||
|
.replace(/\+/, ' ')
|
||||||
|
// Logos will helpfully replace "-" with "–" in its reference spec.
|
||||||
|
.replaceAll(/–/g, '-');
|
||||||
|
const m = ref.match(/((\d+(\+|\s))?[a-zA-Z]+)(\+|\s)?([0-9]+[-0-9]*)?\:?([0-9]+(-?[0-9]+)?)?/);
|
||||||
|
|
||||||
const book = m[1].toLowerCase();
|
const book = m[1].toLowerCase();
|
||||||
const chapter = m[5];
|
const chapter = m[5];
|
||||||
const verses = m[6]?.replaceAll(/–/g, '-');
|
const verses = m[6];
|
||||||
|
|
||||||
if (book === undefined) {
|
if (book === undefined) {
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -69,6 +169,8 @@ function parseRef(ref) {
|
||||||
|
|
||||||
return refdata;
|
return refdata;
|
||||||
}
|
}
|
||||||
|
window.Refs = Refs;
|
||||||
|
window.parseRef = parseRef;
|
||||||
|
|
||||||
class RenderScripture {
|
class RenderScripture {
|
||||||
translation = 'BSB';
|
translation = 'BSB';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue