mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
Fix verse navigation with proper book name capitalization
Added capitalizeBook() helper function that maps user input to proper Title Case book names (Genesis, Job, 1 Samuel, etc.) to fix 404 errors when navigating to verses, chapters, or books with lowercase input. Also changed from non-greedy to greedy regex matching to properly capture multi-word book names like "1 John" and "Song of Solomon" in verse references. Fixes: - "job 1:1" now navigates to /book/Job/chapter/1/verse/1 - "1 john 3:16" works correctly - "romans 8" navigates properly - All book names properly capitalized regardless of user input case 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -190,6 +190,31 @@ section a[href^="/book/"] {
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Helper function to properly capitalize book names
|
||||
function capitalizeBook(bookName) {
|
||||
// Map of lowercase to proper case book names
|
||||
const bookMap = {
|
||||
'genesis': 'Genesis', 'exodus': 'Exodus', 'leviticus': 'Leviticus', 'numbers': 'Numbers',
|
||||
'deuteronomy': 'Deuteronomy', 'joshua': 'Joshua', 'judges': 'Judges', 'ruth': 'Ruth',
|
||||
'1 samuel': '1 Samuel', '2 samuel': '2 Samuel', '1 kings': '1 Kings', '2 kings': '2 Kings',
|
||||
'1 chronicles': '1 Chronicles', '2 chronicles': '2 Chronicles', 'ezra': 'Ezra', 'nehemiah': 'Nehemiah',
|
||||
'esther': 'Esther', 'job': 'Job', 'psalms': 'Psalms', 'psalm': 'Psalms', 'proverbs': 'Proverbs',
|
||||
'ecclesiastes': 'Ecclesiastes', 'song of solomon': 'Song of Solomon', 'isaiah': 'Isaiah',
|
||||
'jeremiah': 'Jeremiah', 'lamentations': 'Lamentations', 'ezekiel': 'Ezekiel', 'daniel': 'Daniel',
|
||||
'hosea': 'Hosea', 'joel': 'Joel', 'amos': 'Amos', 'obadiah': 'Obadiah', 'jonah': 'Jonah',
|
||||
'micah': 'Micah', 'nahum': 'Nahum', 'habakkuk': 'Habakkuk', 'zephaniah': 'Zephaniah',
|
||||
'haggai': 'Haggai', 'zechariah': 'Zechariah', 'malachi': 'Malachi', 'matthew': 'Matthew',
|
||||
'mark': 'Mark', 'luke': 'Luke', 'john': 'John', 'acts': 'Acts', 'romans': 'Romans',
|
||||
'1 corinthians': '1 Corinthians', '2 corinthians': '2 Corinthians', 'galatians': 'Galatians',
|
||||
'ephesians': 'Ephesians', 'philippians': 'Philippians', 'colossians': 'Colossians',
|
||||
'1 thessalonians': '1 Thessalonians', '2 thessalonians': '2 Thessalonians',
|
||||
'1 timothy': '1 Timothy', '2 timothy': '2 Timothy', 'titus': 'Titus', 'philemon': 'Philemon',
|
||||
'hebrews': 'Hebrews', 'james': 'James', '1 peter': '1 Peter', '2 peter': '2 Peter',
|
||||
'1 john': '1 John', '2 john': '2 John', '3 john': '3 John', 'jude': 'Jude', 'revelation': 'Revelation'
|
||||
};
|
||||
return bookMap[bookName.toLowerCase()] || bookName;
|
||||
}
|
||||
|
||||
function handleSearch(event) {
|
||||
event.preventDefault();
|
||||
const input = document.getElementById('verse-lookup-input').value.trim();
|
||||
@@ -203,9 +228,10 @@ function handleSearch(event) {
|
||||
// Examples: "John 3:16", "Psalm 23", "Genesis"
|
||||
|
||||
// Try to match: Book Chapter:Verse
|
||||
let match = input.match(/^(.+?)\s+(\d+):(\d+)$/i);
|
||||
// Use greedy matching (.+) so it captures multi-word book names like "1 John" or "Song of Solomon"
|
||||
let match = input.match(/^(.+)\s+(\d+):(\d+)$/i);
|
||||
if (match) {
|
||||
const book = match[1].trim();
|
||||
const book = capitalizeBook(match[1].trim());
|
||||
const chapter = match[2];
|
||||
const verse = match[3];
|
||||
window.location.href = `/book/${encodeURIComponent(book)}/chapter/${chapter}/verse/${verse}`;
|
||||
@@ -213,9 +239,9 @@ function handleSearch(event) {
|
||||
}
|
||||
|
||||
// Try to match: Book Chapter (go to chapter)
|
||||
match = input.match(/^(.+?)\s+(\d+)$/i);
|
||||
match = input.match(/^(.+)\s+(\d+)$/i);
|
||||
if (match) {
|
||||
const book = match[1].trim();
|
||||
const book = capitalizeBook(match[1].trim());
|
||||
const chapter = match[2];
|
||||
window.location.href = `/book/${encodeURIComponent(book)}/chapter/${chapter}`;
|
||||
return false;
|
||||
@@ -239,7 +265,8 @@ function handleSearch(event) {
|
||||
|
||||
if (hasNumberPrefix || hasMultipleWords || matchesCommonBook) {
|
||||
// Try to navigate to book
|
||||
window.location.href = `/book/${encodeURIComponent(input)}`;
|
||||
const book = capitalizeBook(input);
|
||||
window.location.href = `/book/${encodeURIComponent(book)}`;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user