-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlog
174 lines (155 loc) · 5.27 KB
/
Blog
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Blog</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
padding: 20px 0;
background-color: #333;
color: white;
}
h1 {
margin: 0;
}
.blog-post {
background-color: white;
margin-bottom: 20px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
.blog-post h2 {
margin-top: 0;
}
.new-post-form {
background-color: white;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
border-radius: 5px;
}
label, textarea, input, button {
display: block;
width: 100%;
margin-bottom: 10px;
}
input, textarea {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
button {
padding: 10px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Blog</h1>
</header>
<div class="container">
<!-- Blog Post Form -->
<div class="new-post-form">
<h2>Create a New Blog Post</h2>
<label for="title">Title</label>
<input type="text" id="title" placeholder="Blog post title" required>
<label for="content">Content</label>
<textarea id="content" placeholder="Write your blog post content here" required></textarea>
<button id="submitPost">Publish Post</button>
</div>
<!-- Blog Posts Section -->
<div id="blogPosts">
<h2>Recent Blog Posts</h2>
<!-- Blog posts will be dynamically inserted here -->
</div>
</div>
<script>
const blogPosts = [
{title: "My First Post", content: "Welcome to my blog!"},
{title: "Blog Post 2", content: "This is the second blog post."}
];
// Function to display blog posts
function displayBlogPosts() {
const blogPostsContainer = document.getElementById('blogPosts');
blogPostsContainer.innerHTML = '<h2>Recent Blog Posts</h2>';
blogPosts.forEach(post => {
const postDiv = document.createElement('div');
postDiv.className = 'blog-post';
postDiv.innerHTML = `<h2>${post.title}</h2><p>${post.content}</p>`;
blogPostsContainer.appendChild(postDiv);
});
}
// Add event listener to publish new blog post
document.getElementById('submitPost').addEventListener('click', function() {
const title = document.getElementById('title').value;
const content = document.getElementById('content').value;
if (title && content) {
blogPosts.push({title, content});
displayBlogPosts();
// Clear form after submission
document.getElementById('title').value = '';
document.getElementById('content').value = '';
} else {
alert('Please fill out both title and content!');
}
});
// Display initial blog posts
displayBlogPosts();
</script>
// Function to fetch Medium posts
async function fetchMediumPosts() {
const mediumUserId = 'YOUR_MEDIUM_USER_ID'; // Replace with your Medium user ID
const mediumApiUrl = `https://api.medium.com/v1/users/${mediumUserId}/publications`;
try {
const response = await fetch(mediumApiUrl, {
headers: {
'Authorization': `Bearer YOUR_MEDIUM_INTEGRATION_TOKEN` // Replace with your token
}
});
const data = await response.json();
if (data.data && data.data.length > 0) {
displayMediumPosts(data.data);
} else {
console.log("No Medium posts found.");
}
} catch (error) {
console.error("Error fetching Medium posts:", error);
}
}
// Function to display Medium posts
function displayMediumPosts(posts) {
const blogPostsContainer = document.getElementById('blogPosts');
blogPostsContainer.innerHTML = '<h2>Recent Blog Posts</h2>';
posts.forEach(post => {
const postDiv = document.createElement('div');
postDiv.className = 'blog-post';
postDiv.innerHTML = `<h2>${post.title}</h2><p>${post.content.slice(0, 200)}... <a href="${post.url}" target="_blank">Read more</a></p>`;
blogPostsContainer.appendChild(postDiv);
});
}
// Fetch Medium posts on page load
fetchMediumPosts();
</body>
</html>