fetch('/blog/blog-posts') .then(response => response.json()) .then(posts => { const blogContainer = document.getElementById('blog-container'); posts.forEach(post => { // Create a clickable link wrapping the entire blog preview const blogLink = document.createElement('a'); blogLink.href = `/blog/${post.slug}`; blogLink.className = 'blog-link'; // Optional class for styling blogLink.style.textDecoration = 'none'; // Remove the underline from the link const blogPreview = document.createElement('div'); blogPreview.className = 'blog-preview'; // Create the blog preview with the title, date, and preview blogPreview.innerHTML = `

${post.title}

Published on ${post.date}

${post.preview}...

`; // Append the preview div inside the link, then add the link to the container blogLink.appendChild(blogPreview); blogContainer.appendChild(blogLink); }); }) .catch(error => console.error('Error fetching blog posts:', error));