Skip to content

Commit

Permalink
Merge branch 'main' into caching_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewis84 authored Feb 15, 2024
2 parents 9f346ba + 30b9153 commit be6d92c
Showing 1 changed file with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,48 @@ function ScriptureFeature(props = {}) {
};

function parseBibleReference(reference) {
// This regex handles cases like 'Genesis 1-3' and 'Genesis 1:1-3:24'
const regex = /^([\w\s]+)\s(\d+)(?::(\d+))?(?:-(\d+)(?::(\d+))?)?$/;
const regex = /^([\w\s]+)\s(\d+)(?::(\d+))?(?:-(\d+)?(?::(\d+))?)?$/;
const match = reference.match(regex);

if (!match) {
return null; // Invalid format
}

const [_, book, startChapter, startVerse, endChapter, endVerse] = match;
const [_, book, startChapter, startVerse = '', endChapterOrVerse, endVerse = ''] = match;

let title, verses;
let isRangeWithinSingleChapter = false;
let actualEndVerse = endVerse;

// Determine if it's a range within the same chapter
if (startChapter === endChapterOrVerse || (startVerse && endChapterOrVerse && !endVerse)) {
isRangeWithinSingleChapter = true;
// If endChapterOrVerse is not empty and endVerse is empty, it means endChapterOrVerse is actually the endVerse
actualEndVerse = endChapterOrVerse && !endVerse ? endChapterOrVerse : endVerse;
}

if (endChapter || endVerse) {
// Case for a range
if (endChapter && !endVerse) {
// Range of chapters, e.g., 'Genesis 1-3'
title = `${book} ${startChapter}-${endChapter}`;
verses = `Chapters ${startChapter}-${endChapter}`;
} else if (startChapter !== endChapter) {
// Range of chapters and verses, e.g., 'Genesis 1:1-3:24'
title = `${book} ${startChapter}:${startVerse}-${endChapter}:${endVerse}`;
verses = `Verses ${startChapter}:${startVerse}-${endChapter}:${endVerse}`;
} else {
// Range within a single chapter, e.g., 'Genesis 1:1-24'
title = `${book} ${startChapter}:${startVerse}-${endVerse}`;
verses = `Verses ${startChapter}:${startVerse}-${endVerse}`;
}
if (isRangeWithinSingleChapter) {
// Range within the same chapter
title = `${book} ${startChapter}:${startVerse}-${actualEndVerse}`;
verses = `Verses ${startChapter}:${startVerse}-${actualEndVerse}`;
} else if (startVerse && endVerse) {
// Range spans chapters and verses
title = `${book} ${startChapter}:${startVerse}-${endChapterOrVerse}:${endVerse}`;
verses = `Verses ${startChapter}:${startVerse}-${endChapterOrVerse}:${endVerse}`;
} else if (!startVerse && endChapterOrVerse) {
// Range spans entire chapters
title = `${book} ${startChapter}-${endChapterOrVerse}`;
verses = `Chapters ${startChapter}-${endChapterOrVerse}`;
} else {
// Single chapter and verse, e.g., 'Genesis 1:1'
title = `${book} ${startChapter}${startVerse ? `:${startVerse}` : ''}`;
// Single chapter or verse
title = `${book} ${startChapter}${startVerse ? ':' + startVerse : ''}`;
verses = startVerse ? `Verse ${startChapter}:${startVerse}` : `Chapter ${startChapter}`;
}

const result = {
return {
title,
verses,
};

return result;
}

const ScriptureItem = ({ scripture }) => {
Expand Down

0 comments on commit be6d92c

Please sign in to comment.