Analytics: unique visitors this week + probed-URLs list; Scripture Index: most-studied strip + print; admin warning for unparseable passage references; v2.44.0
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6a5d525d6e
commit
e9d9dd0d50
13 files changed
+143
-9
No files matched your search
+32
-1
@@ -67,7 +67,7 @@ export const BIBLE_BOOKS = [
|
||||
{ id: 'TH2', name: '2 Thessalonians', aliases: ['2 thess'] },
|
||||
{ id: 'TI1', name: '1 Timothy', aliases: ['1 tim'] },
|
||||
{ id: 'TI2', name: '2 Timothy', aliases: ['2 tim'] },
|
||||
{ id: 'TIT', name: 'Titus' },
|
||||
{ id: 'TIT', name: 'Titus', aliases: ['tit'] },
|
||||
{ id: 'PHM', name: 'Philemon', aliases: ['philem'] },
|
||||
{ id: 'HEB', name: 'Hebrews', aliases: ['heb'] },
|
||||
{ id: 'JAM', name: 'James', aliases: ['jas'] },
|
||||
@@ -85,3 +85,34 @@ export function bookNumberFor(usfmId) {
|
||||
const index = BIBLE_BOOKS.findIndex(b => b.id === usfmId)
|
||||
return index === -1 ? null : index + 1
|
||||
}
|
||||
|
||||
let referenceBookLookup = null
|
||||
|
||||
/**
|
||||
* Checks a passage reference the way the Scripture Index and passage fetch read it.
|
||||
* `bookHint` is the study's Bible Book field (or slug) and is used when the reference
|
||||
* has no book of its own ("1:1-2"). Returns null when it will work, otherwise a short
|
||||
* message explaining what to change.
|
||||
*/
|
||||
export function checkPassageReference(reference, bookHint) {
|
||||
if (!referenceBookLookup) {
|
||||
referenceBookLookup = new Set()
|
||||
for (const b of BIBLE_BOOKS) {
|
||||
for (const key of [b.name.toLowerCase(), ...(b.aliases ?? [])]) {
|
||||
referenceBookLookup.add(key)
|
||||
referenceBookLookup.add(key.replace(/\s+/g, ''))
|
||||
}
|
||||
}
|
||||
}
|
||||
const clean = String(reference ?? '').replace(/[–—]/g, '-').replace(/(\d)[a-z]\b/gi, '$1').trim()
|
||||
if (!clean) return null
|
||||
const m = clean.match(/^(?:(.*?)\s+)?(\d+):(\d+)(?:-(?:(\d+):)?(\d+))?$/)
|
||||
if (!m) return 'Use the form 1:1-2 (chapter:verse, optional range). It will be listed under "Other references" in the Scripture Index until fixed.'
|
||||
const book = (m[1] ?? String(bookHint ?? '')).toLowerCase().replace(/\.\s*/g, ' ').trim()
|
||||
if (!book || !referenceBookLookup.has(book)) {
|
||||
return m[1]
|
||||
? `"${m[1]}" is not a recognized Bible book name.`
|
||||
: 'Set this study\'s "Bible Book" field (e.g. titus) so this reference can be matched to a book.'
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user