forked from Aditya-269/BloggingSite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle.js
More file actions
17 lines (16 loc) · 746 Bytes
/
single.js
File metadata and controls
17 lines (16 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
document.addEventListener("DOMContentLoaded", () => {
const blogs = JSON.parse(localStorage.getItem("blogs")) || [];
const currentPostIndex = localStorage.getItem("currentPost");
const contentContainer = document.getElementById("blog-content");
if (currentPostIndex !== null && blogs[currentPostIndex]) {
const post = blogs[currentPostIndex];
contentContainer.innerHTML = `
<h1>${post.title}</h1>
${post.image ? `<img src="${post.image}" alt="Blog Image" style="max-width: 100%;">` : ""}
<p>${post.body}</p>
<a href="index.html">Back to Blog List</a>
`;
} else {
contentContainer.innerHTML = "<p>No content found.</p>";
}
});