Skip to content

Commit 2583a8a

Browse files
authored
Add files via upload
1 parent c558590 commit 2583a8a

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

public/main.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
function log(message, inline = false) {
2-
const extraStyle = inline ? "" : "display:inline-block; padding: 10px;";
3-
const style = "color: white; background: black; font-family: monospace; font-size: 20px; " + extraStyle;
4-
console.log(`%c${message}`, style);
5-
}
6-
7-
log("hey kitten");
8-
log("looking through my code??");
9-
log("go check out the repository:");
10-
console.log('%chttps://www.github.com/sippedaway/sipped.org', "font-size: 20px;");
11-
log('have fun :) email me: hello@sipped.org');
12-
131
document.addEventListener('DOMContentLoaded', () => {
142
if (document.body.id === 'home') {
153
loadPosts();
@@ -132,6 +120,19 @@ function loadPosts() {
132120
.catch(err => console.error('Error loading posts:', err));
133121
}
134122

123+
async function loadPostViews(postId) {
124+
try {
125+
const response = await fetch(`/api/views/${postId}`);
126+
const data = await response.json();
127+
const viewsDiv = document.querySelector('.views');
128+
if (viewsDiv && data.count) {
129+
viewsDiv.innerHTML = `<i class="fas fa-eye"></i> ${data.count} ${data.count === 1 ? 'view' : 'views'}`;
130+
}
131+
} catch (err) {
132+
console.error('Error fetching view count:', err);
133+
}
134+
}
135+
135136
function loadSinglePost() {
136137
const postId = window.location.pathname.split('/').pop();
137138
if (!postId) {
@@ -157,7 +158,10 @@ function loadSinglePost() {
157158
container.innerHTML = `
158159
${assetId ? `<span class="asset-placeholder asset-placeholder-header" data-asset-id="${assetId}">Loading media...</span>` : ''}
159160
<h2>${post.fields.title}</h2>
160-
<small>${formatDate(post.fields.date)}</small>
161+
<div class="post-header">
162+
<small>${formatDate(post.fields.date)}</small>
163+
<div class="views"><i class="fas fa-eye"></i> Loading views...</div>
164+
</div>
161165
${post.fields.summary ? `
162166
<div class="summary-dropdown">
163167
<button class="summary-button" onclick="toggleSummary(this);">
@@ -170,6 +174,7 @@ function loadSinglePost() {
170174
<div>${postContentHtml}</div>
171175
`;
172176
loadEmbeddedAssets();
177+
loadPostViews(postId);
173178
})
174179
.catch(err => console.error('Error loading post:', err));
175180
}
@@ -323,4 +328,4 @@ function renderText(textArray) {
323328
}
324329
return "";
325330
}).join('');
326-
}
331+
}

public/styles.css

+6
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ main {
308308
color: var(--primary-color)
309309
}
310310

311+
.post-header {
312+
display: flex;
313+
align-items: center;
314+
gap: 3%;
315+
}
316+
311317
.summary-dropdown {
312318
margin: 1rem 0;
313319
}

0 commit comments

Comments
 (0)