Enter Password to Post

// Replace the try-catch block in your post.html with this: try { // Fetch existing posts const response = await fetch('posts.json'); if (!response.ok) { throw new Error(`Failed to fetch posts: ${response.status} ${response.statusText}`); } const data = await response.json(); const posts = data.posts || []; // Add new post posts.push(postData); // Save updated posts back to file const saveResponse = await fetch('save_post.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ posts: posts }) }); if (!saveResponse.ok) { const errorText = await saveResponse.text(); throw new Error(`Failed to save post: ${saveResponse.status} ${saveResponse.statusText}\n${errorText}`); } alert('Post published successfully!'); blogPostForm.reset(); imagePreview.innerHTML = ''; window.location.href = 'index.html#blog'; } catch (error) { console.error('Error publishing post:', error); alert('Failed to publish post. Error: ' + error.message); }