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
-
13
1
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
14
2
if ( document . body . id === 'home' ) {
15
3
loadPosts ( ) ;
@@ -132,6 +120,19 @@ function loadPosts() {
132
120
. catch ( err => console . error ( 'Error loading posts:' , err ) ) ;
133
121
}
134
122
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
+
135
136
function loadSinglePost ( ) {
136
137
const postId = window . location . pathname . split ( '/' ) . pop ( ) ;
137
138
if ( ! postId ) {
@@ -157,7 +158,10 @@ function loadSinglePost() {
157
158
container . innerHTML = `
158
159
${ assetId ? `<span class="asset-placeholder asset-placeholder-header" data-asset-id="${ assetId } ">Loading media...</span>` : '' }
159
160
<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>
161
165
${ post . fields . summary ? `
162
166
<div class="summary-dropdown">
163
167
<button class="summary-button" onclick="toggleSummary(this);">
@@ -170,6 +174,7 @@ function loadSinglePost() {
170
174
<div>${ postContentHtml } </div>
171
175
` ;
172
176
loadEmbeddedAssets ( ) ;
177
+ loadPostViews ( postId ) ;
173
178
} )
174
179
. catch ( err => console . error ( 'Error loading post:' , err ) ) ;
175
180
}
@@ -323,4 +328,4 @@ function renderText(textArray) {
323
328
}
324
329
return "" ;
325
330
} ) . join ( '' ) ;
326
- }
331
+ }
0 commit comments