@@ -77,6 +77,10 @@ function nav(id){
7777 }
7878 document . getElementById ( `${ id } Body` ) . classList . remove ( 'leave' ) ;
7979 document . getElementById ( `${ id } Body` ) . classList . add ( 'onload' ) ;
80+
81+ if ( ( id != 'search' ) && ( id != 'post' ) ) {
82+ sendAnalytics ( id ) ;
83+ }
8084}
8185
8286function openPost ( t , type ) {
@@ -100,10 +104,11 @@ function openPost(t,type) {
100104 <h1>` + pp . title + `</h1>
101105 <p class="date">Posted on ` + pp . date + `</p>
102106 </div>
107+ <div class="post-content">
103108 ` + pp . body + `
109+ </div>
104110 </div>
105111 `
106- sendAnalytics ( pp , type ) ;
107112
108113 const parentElement = document . querySelector ( '#postBody' ) ;
109114 const childElement = parentElement . querySelector ( '.sideBar' ) ;
@@ -112,6 +117,7 @@ function openPost(t,type) {
112117 parentElement . querySelector ( '.article' ) . style . width = "100%"
113118 }
114119
120+ sendAnalytics ( 'post' ) ;
115121}
116122
117123function countWords ( html ) {
@@ -157,16 +163,12 @@ function initData() {
157163
158164 document . getElementById ( "BlogPosts" ) . innerHTML = ``
159165 for ( let i = postData . length - 1 ; i >= 0 ; i -- ) {
160- document . getElementById ( "BlogPosts" ) . innerHTML += `
161- <div class="postPreview" onclick="openPost('${ i } ','blog')"><div class="previewLeft"><h1>` + JSON . parse ( postData [ i ] ) . title + `</h1>
162- <p>Posted on ${ JSON . parse ( postData [ i ] ) . date } </p><p>${ countWords ( JSON . parse ( postData [ i ] ) . body ) } words</p></div><div class="postPreviewParagraph">${ postPreview ( JSON . parse ( postData [ i ] ) . body ) } ...</div></div>`
166+ document . getElementById ( "BlogPosts" ) . innerHTML += generatePostPreview ( 'blog' , JSON . parse ( postData [ i ] ) , i )
163167 }
164168
165169 document . getElementById ( "ProjectPosts" ) . innerHTML = ``
166170 for ( let i = projectData . length - 1 ; i >= 0 ; i -- ) {
167- document . getElementById ( "ProjectPosts" ) . innerHTML += `
168- <div class="postPreview" onclick="openPost('${ i } ','projects')"><div class="previewLeft"><h1>` + JSON . parse ( projectData [ i ] ) . title + `</h1>
169- <p>Posted on ${ JSON . parse ( projectData [ i ] ) . date } </p><p>${ countWords ( JSON . parse ( projectData [ i ] ) . body ) } words</p></div><div class="postPreviewParagraph">${ postPreview ( JSON . parse ( projectData [ i ] ) . body ) } ...</div></div>`
171+ document . getElementById ( "ProjectPosts" ) . innerHTML += generatePostPreview ( 'projects' , JSON . parse ( projectData [ i ] ) , i )
170172 }
171173
172174 load ( ) ;
@@ -177,15 +179,11 @@ function initData() {
177179
178180 document . getElementById ( "BlogPosts" ) . innerHTML = ``
179181 for ( let i = postData . length - 1 ; i >= 0 ; i -- ) {
180- document . getElementById ( "BlogPosts" ) . innerHTML += `
181- <div class="postPreview" onclick="openPost('${ i } ','blog')"><h1>` + JSON . parse ( postData [ i ] ) . title + `</h1>
182- <p>Posted on ${ JSON . parse ( postData [ i ] ) . date } </p></div>`
182+ document . getElementById ( "BlogPosts" ) . innerHTML += generatePostPreview ( 'blog' , postData [ i ] , i )
183183 }
184184 document . getElementById ( "ProjectPosts" ) . innerHTML = ``
185185 for ( let i = projectData . length - 1 ; i >= 0 ; i -- ) {
186- document . getElementById ( "ProjectPosts" ) . innerHTML += `
187- <div class="postPreview" onclick="openPost('${ i } ','projects')"><h1>` + JSON . parse ( projectData [ i ] ) . title + `</h1>
188- <p>Posted on ${ JSON . parse ( projectData [ i ] ) . date } </p></div>`
186+ document . getElementById ( "ProjectPosts" ) . innerHTML += generatePostPreview ( 'projects' , projectData [ i ] , i ) ;
189187 }
190188
191189 load ( ) ;
@@ -199,15 +197,13 @@ function search(input){
199197 for ( let i = postData . length - 1 ; i >= 0 ; i -- ) {
200198 let opt = JSON . parse ( postData [ i ] )
201199 if ( JSON . stringify ( opt ) . toLowerCase ( ) . includes ( input . toLowerCase ( ) ) ) {
202- output . innerHTML += `<div class="postPreview" onclick="openPost('${ i } ','blog')"><h1>` + opt . title + `</h1>
203- <p>Posted on ` + opt . date + `</p></div>`
200+ output . innerHTML += generatePostPreview ( 'blog' , opt , i )
204201 }
205202 }
206203 for ( let i = projectData . length - 1 ; i >= 0 ; i -- ) {
207204 let opt = JSON . parse ( projectData [ i ] )
208205 if ( JSON . stringify ( opt ) . toLowerCase ( ) . includes ( input . toLowerCase ( ) ) ) {
209- output . innerHTML += `<div class="postPreview" onclick="openPost('${ i } ','projects')"><h1>` + opt . title + `</h1>
210- <p>Posted on ` + opt . date + `</p></div>`
206+ output . innerHTML += generatePostPreview ( 'projects' , opt , i )
211207 }
212208 }
213209 if ( output . innerHTML === `` ) {
@@ -222,6 +218,13 @@ function search(input){
222218
223219 // Push the new URL to the browser history
224220 window . history . pushState ( { path : newUrl } , '' , newUrl ) ;
221+
222+ sendAnalytics ( 'search' ) ;
223+ }
224+
225+ function generatePostPreview ( type , data , i ) {
226+ return `<div class="postPreview" onclick="openPost('${ i } ','${ type } ')"><div class="previewLeft"><h1>` + data . title + `</h1>
227+ <p>Posted on ${ data . date } </p><p>${ countWords ( data . body ) } words</p></div><div class="postPreviewParagraph">${ postPreview ( data . body ) } ...</div></div>`
225228}
226229
227230function LoadVFX ( ) {
0 commit comments