-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.html
More file actions
145 lines (123 loc) · 3.87 KB
/
post.html
File metadata and controls
145 lines (123 loc) · 3.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title id="pageTitle">Post - kljukua.com</title>
<link rel="stylesheet" href="style.css">
<style>
.post-content {
max-width: 700px;
margin: 0 auto;
padding: 40px 20px;
}
.post-header {
margin-bottom: 40px;
text-align: center;
}
.post-title {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 12px;
color: #000000;
}
.post-meta {
color: #666666;
font-size: 1.1rem;
margin-bottom: 20px;
}
.back-link {
display: inline-block;
color: #000000;
text-decoration: none;
font-weight: 500;
margin-bottom: 20px;
}
.back-link:hover {
text-decoration: underline;
}
.post-body {
font-size: 1.1rem;
line-height: 1.8;
color: #333333;
white-space: pre-line;
}
.post-body h1, .post-body h2, .post-body h3 {
color: #000000;
margin-top: 30px;
margin-bottom: 15px;
}
.post-body p {
margin-bottom: 20px;
}
.error-message {
text-align: center;
color: #666666;
font-size: 1.1rem;
margin-top: 60px;
}
</style>
</head>
<body>
<div class="post-content">
<a href="index.html" class="back-link">← Back to Blog</a>
<article id="postArticle">
<div class="error-message" id="errorMessage" style="display: none;">
<p>Post not found.</p>
</div>
</article>
</div>
<script>
document.addEventListener('DOMContentLoaded', loadPost);
async function loadPost() {
const urlParams = new URLSearchParams(window.location.search);
const slug = urlParams.get('slug');
if (!slug) {
showError();
return;
}
try {
const response = await fetch('posts.json');
const posts = await response.json();
const post = posts.find(p => p.slug === slug);
if (!post) {
showError();
return;
}
displayPost(post);
} catch (error) {
console.error('Error loading post:', error);
showError();
}
}
function displayPost(post) {
document.getElementById('pageTitle').textContent = `${post.title} - kljukua.com`;
// Use HTML content if available (from web editor), otherwise use plain text content
const content = post.htmlContent || escapeHtml(post.content);
document.getElementById('postArticle').innerHTML = `
<header class="post-header">
<h1 class="post-title">${escapeHtml(post.title)}</h1>
<div class="post-meta">${formatDate(post.date)}</div>
</header>
<div class="post-body">${content}</div>
`;
}
function showError() {
document.getElementById('errorMessage').style.display = 'block';
}
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
</script>
</body>
</html>