`;
$results.append(resultHtml);
});
// Add "Load More" button if we have enough results
if (results.length >= 10) {
$results.append(`
`);
}
// Scroll to results if this is a new search
if (!append) {
$('html, body').animate({
scrollTop: $results.offset().top - 100
}, 500);
}
}
/**
* Render books list for a result item
*/
function renderBooksList(books) {
if (!books || books.length === 0) {
return '';
}
let html = '
';
html += 'Books: ';
books.forEach(function(book) {
html += `${book}`;
});
html += '
';
return html;
}
/**
* Render topics list for a result item
*/
function renderTopicsList(topics) {
if (!topics || topics.length === 0) {
return '';
}
let html = '
';
html += 'Topics: ';
topics.forEach(function(topic) {
html += `${topic}`;
});
html += '
';
return html;
}
/**
* Highlight search term in text
*/
function highlightSearchTerm(text) {
const searchTerm = $('#search-term').val().trim();
if (!searchTerm || !text) {
return text;
}
// Split search term into words for better matching
const terms = searchTerm.split(' ').filter(term => term.length > 2);
if (terms.length === 0) {
return text;
}
// Create a regex to match all search terms
const pattern = new RegExp('(' + terms.join('|') + ')', 'gi');
return text.replace(pattern, '$1');
}
/**
* Format post type into readable label
*/
function formatPostTypeLabel(postType) {
const labels = {
'reading_hub': 'Daily Readings',
'commentary': 'Commentary',
'devotionals': 'Devotionals',
'proverb_nuggets': 'Proverb Nuggets',
'topic_studies': 'Topic Studies',
'memory_verses': 'Memory Verses'
};
return labels[postType] || postType.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
}
})(jQuery);