${primaryCategory}
By ${author}
${post.title.rendered}
${this.stripHtml(post.excerpt.rendered)}
`;
return article;
}
loadMorePosts() {
this.currentPage++;
this.renderPosts();
}
updateLoadMoreButton() {
const totalShown = this.currentPage * this.postsPerPage;
if (totalShown >= this.filteredPosts.length) {
this.loadMoreBtn.style.display = 'none';
} else {
this.loadMoreBtn.style.display = 'block';
}
}
updateResultsInfo() {
const total = this.filteredPosts.length;
const shown = Math.min(this.currentPage * this.postsPerPage, total);
if (this.searchTerm) {
this.resultsCount.textContent = `${total} result${total !== 1 ? 's' : ''} found for "${this.searchTerm}"`;
} else {
this.resultsCount.textContent = `Showing ${shown} of ${total} post${total !== 1 ? 's' : ''}`;
}
}
stripHtml(html) {
const div = document.createElement('div');
div.innerHTML = html;
return div.textContent || div.innerText || '';
}
formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
showLoading() {
this.loadingSpinner.style.display = 'flex';
this.blogGrid.style.display = 'none';
this.noResults.style.display = 'none';
}
hideLoading() {
this.loadingSpinner.style.display = 'none';
this.blogGrid.style.display = 'grid';
}
showNoResults() {
this.noResults.style.display = 'block';
this.blogGrid.style.display = 'none';
this.loadMoreBtn.style.display = 'none';
}
hideNoResults() {
this.noResults.style.display = 'none';
}
}
// Initialize the blog manager when the page loads
document.addEventListener('DOMContentLoaded', () => {
new BlogManager();
});