-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
181 lines (166 loc) · 5.31 KB
/
index.html
File metadata and controls
181 lines (166 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kyle Ketterer</title>
<style>
body {
background-color: black;
color: white;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
text-align: center;
padding: 20px;
}
nav {
text-align: center;
background-color: #333;
}
nav a {
text-decoration: none;
color: white;
padding: 10px 20px;
cursor: pointer;
}
nav a:hover {
background-color: #555;
}
section {
display: none;
padding: 50px;
}
#home-section {
display: block;
}
#blog-section {
display: none;
}
#blog-input {
width: 100%;
}
.blog-entry {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.blog-title {
font-size: 20px;
}
.blog-date {
font-style: italic;
}
.delete-button {
background-color: red;
color: white;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<h1>Your Website</h1>
</header>
<nav>
<a onclick="showSection('home')">Home</a>
<a onclick="showSection('portfolio')">Portfolio</a>
<a onclick="showSection('blog')">Blog</a>
</nav>
<section id="home-section">
<h2>About me</h2>
<p>I am cool</p>
</section>
<section id="portfolio">
<h2>Portfolio Section</h2>
<p>This is the portfolio section of your website.</p>
</section>
<section id="blog-section">
<h2>Blog Section</h2>
<input type="text" id="blog-title" placeholder="Enter the title" />
<textarea id="blog-input" placeholder="Enter your blog post"></textarea>
<input type="file" id="blog-image" accept="image/*" />
<button onclick="addBlogPost()">Submit</button>
<div id="blog-posts"></div>
</section>
<script>
function showSection(sectionId) {
var sections = document.querySelectorAll("section");
for (var i = 0; i < sections.length; i++) {
sections[i].style.display = "none";
}
var selectedSection = document.getElementById(sectionId + "-section");
selectedSection.style.display = "block";
}
function displayBlogPosts(posts) {
var blogPosts = document.getElementById("blog-posts");
blogPosts.innerHTML = "";
if (posts && posts.length > 0) {
posts.forEach(function (post, index) {
var postDiv = document.createElement("div");
postDiv.className = "blog-entry";
postDiv.innerHTML = `
<h3 class="blog-title">${post.title}</h3>
<p class="blog-date">${post.date}</p>
<p>${post.content}</p>
<img src="${post.image}" alt="Blog Image" />
<button class="delete-button" onclick="deleteBlogPost(${index})">Delete</button>
`;
blogPosts.appendChild(postDiv);
});
}
}
function addBlogPost() {
var blogTitleInput = document.getElementById("blog-title");
var blogInput = document.getElementById("blog-input");
var blogImageInput = document.getElementById("blog-image");
var currentDate = new Date();
var formattedDate = currentDate.toLocaleDateString();
var imageFile = blogImageInput.files[0]; // Get the selected image file
// Check if an image is selected
if (imageFile) {
// Upload the image to the server (you'll need server-side logic for this)
// After successful upload, you'll receive a URL for the uploaded image.
// For now, let's assume you receive a placeholder URL for the image.
var imageUrl = "https://example.com/path/to/uploaded/image.jpg";
} else {
// No image selected
var imageUrl = ""; // Set a default image URL or handle this case accordingly
}
function loadBlogPostsFromJSON() {
var storedPosts = localStorage.getItem("blogPosts");
return storedPosts ? JSON.parse(storedPosts) : null;
}
function saveBlogPostsToJSON(posts) {
localStorage.setItem("blogPosts", JSON.stringify(posts));
}
function deleteBlogPost(index) {
var existingPosts = loadBlogPostsFromJSON() || [];
existingPosts.splice(index, 1);
saveBlogPostsToJSON(existingPosts);
displayBlogPosts(existingPosts);
}
var newPost = {
title: blogTitleInput.value,
date: formattedDate,
content: blogInput.value,
image: imageUrl, // Use the received image URL here
};
var existingPosts = loadBlogPostsFromJSON() || [];
existingPosts.unshift(newPost);
saveBlogPostsToJSON(existingPosts);
blogTitleInput.value = "";
blogInput.value = "";
blogImageInput.value = "";
displayBlogPosts(existingPosts);
}
window.onload = function () {
var existingPosts = loadBlogPostsFromJSON();
displayBlogPosts(existingPosts);
};
</script>
</body>
</html>