@@ -26,11 +26,11 @@ type Blog struct {
26
26
db * gorm.DB
27
27
auth auth.IAuth
28
28
Version string
29
- scholar scholar.Scholar
29
+ scholar * scholar.Scholar
30
30
}
31
31
32
32
// New constructs an Admin API
33
- func New (db * gorm.DB , auth auth.IAuth , version string , scholar scholar.Scholar ) Blog {
33
+ func New (db * gorm.DB , auth auth.IAuth , version string , scholar * scholar.Scholar ) Blog {
34
34
api := Blog {db , auth , version , scholar }
35
35
return api
36
36
}
@@ -174,20 +174,20 @@ func (b Blog) NoRoute(c *gin.Context) {
174
174
if err == nil && post != nil {
175
175
if b .auth .IsAdmin (c ) {
176
176
c .HTML (http .StatusOK , "post-admin.html" , gin.H {
177
- "logged_in" : b .auth .IsLoggedIn (c ),
178
- "is_admin" : b .auth .IsAdmin (c ),
179
- "post" : post ,
180
- "version" : b .Version ,
181
- "recent" : b .GetLatest (),
177
+ "logged_in" : b .auth .IsLoggedIn (c ),
178
+ "is_admin" : b .auth .IsAdmin (c ),
179
+ "post" : post ,
180
+ "version" : b .Version ,
181
+ "recent" : b .GetLatest (),
182
182
"admin_page" : false ,
183
183
})
184
184
} else {
185
185
c .HTML (http .StatusOK , "post.html" , gin.H {
186
- "logged_in" : b .auth .IsLoggedIn (c ),
187
- "is_admin" : b .auth .IsAdmin (c ),
188
- "post" : post ,
189
- "version" : b .Version ,
190
- "recent" : b .GetLatest (),
186
+ "logged_in" : b .auth .IsLoggedIn (c ),
187
+ "is_admin" : b .auth .IsAdmin (c ),
188
+ "post" : post ,
189
+ "version" : b .Version ,
190
+ "recent" : b .GetLatest (),
191
191
"admin_page" : false ,
192
192
})
193
193
}
@@ -207,7 +207,7 @@ func (b Blog) NoRoute(c *gin.Context) {
207
207
"description" : "The page at '" + c .Request .URL .String () + "' was not found" ,
208
208
"version" : b .Version ,
209
209
"recent" : b .GetLatest (),
210
- "admin_page" : false ,
210
+ "admin_page" : false ,
211
211
})
212
212
}
213
213
@@ -216,24 +216,24 @@ func (b Blog) NoRoute(c *gin.Context) {
216
216
// need to modify this function
217
217
func (b Blog ) Home (c * gin.Context ) {
218
218
c .HTML (http .StatusOK , "home.html" , gin.H {
219
- "logged_in" : b .auth .IsLoggedIn (c ),
220
- "is_admin" : b .auth .IsAdmin (c ),
221
- "version" : b .Version ,
222
- "title" : "Software Engineer" ,
223
- "recent" : b .GetLatest (),
219
+ "logged_in" : b .auth .IsLoggedIn (c ),
220
+ "is_admin" : b .auth .IsAdmin (c ),
221
+ "version" : b .Version ,
222
+ "title" : "Software Engineer" ,
223
+ "recent" : b .GetLatest (),
224
224
"admin_page" : false ,
225
225
})
226
226
}
227
227
228
228
// Posts is the index page for blog posts
229
229
func (b Blog ) Posts (c * gin.Context ) {
230
230
c .HTML (http .StatusOK , "posts.html" , gin.H {
231
- "logged_in" : b .auth .IsLoggedIn (c ),
232
- "is_admin" : b .auth .IsAdmin (c ),
233
- "posts" : b .GetPosts (false ),
234
- "version" : b .Version ,
235
- "title" : "Posts" ,
236
- "recent" : b .GetLatest (),
231
+ "logged_in" : b .auth .IsLoggedIn (c ),
232
+ "is_admin" : b .auth .IsAdmin (c ),
233
+ "posts" : b .GetPosts (false ),
234
+ "version" : b .Version ,
235
+ "title" : "Posts" ,
236
+ "recent" : b .GetLatest (),
237
237
"admin_page" : false ,
238
238
})
239
239
}
@@ -248,15 +248,15 @@ func (b Blog) Post(c *gin.Context) {
248
248
"version" : b .Version ,
249
249
"title" : "Post Not Found" ,
250
250
"recent" : b .GetLatest (),
251
- "admin_page" : false ,
251
+ "admin_page" : false ,
252
252
})
253
253
} else {
254
254
c .HTML (http .StatusOK , "post.html" , gin.H {
255
- "logged_in" : b .auth .IsLoggedIn (c ),
256
- "is_admin" : b .auth .IsAdmin (c ),
257
- "post" : post ,
258
- "version" : b .Version ,
259
- "recent" : b .GetLatest (),
255
+ "logged_in" : b .auth .IsLoggedIn (c ),
256
+ "is_admin" : b .auth .IsAdmin (c ),
257
+ "post" : post ,
258
+ "version" : b .Version ,
259
+ "recent" : b .GetLatest (),
260
260
"admin_page" : false ,
261
261
})
262
262
//if b.auth.IsAdmin(c) {
@@ -288,17 +288,17 @@ func (b Blog) Tag(c *gin.Context) {
288
288
"version" : b .Version ,
289
289
"title" : "Tag '" + tag + "' Not Found" ,
290
290
"recent" : b .GetLatest (),
291
- "admin_page" : false ,
291
+ "admin_page" : false ,
292
292
})
293
293
} else {
294
294
c .HTML (http .StatusOK , "tag.html" , gin.H {
295
- "logged_in" : b .auth .IsLoggedIn (c ),
296
- "is_admin" : b .auth .IsAdmin (c ),
297
- "posts" : posts ,
298
- "tag" : tag ,
299
- "version" : b .Version ,
300
- "title" : "Posts with Tag '" + tag + "'" ,
301
- "recent" : b .GetLatest (),
295
+ "logged_in" : b .auth .IsLoggedIn (c ),
296
+ "is_admin" : b .auth .IsAdmin (c ),
297
+ "posts" : posts ,
298
+ "tag" : tag ,
299
+ "version" : b .Version ,
300
+ "title" : "Posts with Tag '" + tag + "'" ,
301
+ "recent" : b .GetLatest (),
302
302
"admin_page" : false ,
303
303
})
304
304
}
@@ -307,59 +307,61 @@ func (b Blog) Tag(c *gin.Context) {
307
307
// Tags is the index page for all Tags
308
308
func (b Blog ) Tags (c * gin.Context ) {
309
309
c .HTML (http .StatusOK , "tags.html" , gin.H {
310
- "version" : b .Version ,
311
- "title" : "Tags" ,
312
- "tags" : b .getTags (),
313
- "recent" : b .GetLatest (),
310
+ "version" : b .Version ,
311
+ "title" : "Tags" ,
312
+ "tags" : b .getTags (),
313
+ "recent" : b .GetLatest (),
314
314
"admin_page" : false ,
315
315
})
316
316
}
317
317
318
318
// Speaking is the index page for presentations
319
319
func (b Blog ) Speaking (c * gin.Context ) {
320
320
c .HTML (http .StatusOK , "presentations.html" , gin.H {
321
- "logged_in" : b .auth .IsLoggedIn (c ),
322
- "is_admin" : b .auth .IsAdmin (c ),
323
- "version" : b .Version ,
324
- "title" : "Presentations and Speaking" ,
325
- "recent" : b .GetLatest (),
321
+ "logged_in" : b .auth .IsLoggedIn (c ),
322
+ "is_admin" : b .auth .IsAdmin (c ),
323
+ "version" : b .Version ,
324
+ "title" : "Presentations and Speaking" ,
325
+ "recent" : b .GetLatest (),
326
326
"admin_page" : false ,
327
327
})
328
328
}
329
329
330
330
// Speaking is the index page for research publications
331
331
func (b Blog ) Research (c * gin.Context ) {
332
+ articles := b .scholar .QueryProfileWithMemoryCache ("SbUmSEAAAAAJ" , 50 )
333
+ b .scholar .SaveCache ("profiles.json" , "articles.json" )
332
334
c .HTML (http .StatusOK , "research.html" , gin.H {
333
- "logged_in" : b .auth .IsLoggedIn (c ),
334
- "is_admin" : b .auth .IsAdmin (c ),
335
- "version" : b .Version ,
336
- "title" : "Research Publications" ,
337
- "recent" : b .GetLatest (),
338
- "articles" : b . scholar . QueryProfileWithCache ( "SbUmSEAAAAAJ" , 1 ) ,
335
+ "logged_in" : b .auth .IsLoggedIn (c ),
336
+ "is_admin" : b .auth .IsAdmin (c ),
337
+ "version" : b .Version ,
338
+ "title" : "Research Publications" ,
339
+ "recent" : b .GetLatest (),
340
+ "articles" : articles ,
339
341
"admin_page" : false ,
340
342
})
341
343
}
342
344
343
345
// Projects is the index page for projects / code
344
346
func (b Blog ) Projects (c * gin.Context ) {
345
347
c .HTML (http .StatusOK , "projects.html" , gin.H {
346
- "logged_in" : b .auth .IsLoggedIn (c ),
347
- "is_admin" : b .auth .IsAdmin (c ),
348
- "version" : b .Version ,
349
- "title" : "Projects" ,
350
- "recent" : b .GetLatest (),
348
+ "logged_in" : b .auth .IsLoggedIn (c ),
349
+ "is_admin" : b .auth .IsAdmin (c ),
350
+ "version" : b .Version ,
351
+ "title" : "Projects" ,
352
+ "recent" : b .GetLatest (),
351
353
"admin_page" : false ,
352
354
})
353
355
}
354
356
355
357
// About is the about page
356
358
func (b Blog ) About (c * gin.Context ) {
357
359
c .HTML (http .StatusOK , "about.html" , gin.H {
358
- "logged_in" : b .auth .IsLoggedIn (c ),
359
- "is_admin" : b .auth .IsAdmin (c ),
360
- "version" : b .Version ,
361
- "title" : "About" ,
362
- "recent" : b .GetLatest (),
360
+ "logged_in" : b .auth .IsLoggedIn (c ),
361
+ "is_admin" : b .auth .IsAdmin (c ),
362
+ "version" : b .Version ,
363
+ "title" : "About" ,
364
+ "recent" : b .GetLatest (),
363
365
"admin_page" : false ,
364
366
})
365
367
}
@@ -374,7 +376,7 @@ func (b Blog) Archives(c *gin.Context) {
374
376
"byYear" : b .getArchivesByYear (),
375
377
"byYearMonth" : b .getArchivesByYearMonth (),
376
378
"recent" : b .GetLatest (),
377
- "admin_page" : false ,
379
+ "admin_page" : false ,
378
380
})
379
381
}
380
382
@@ -416,11 +418,11 @@ func (b Blog) Login(c *gin.Context) {
416
418
if err != nil {
417
419
//todo: handle better - perhaps return error to browser
418
420
c .HTML (http .StatusInternalServerError , "Error loading .env file: " + err .Error (), gin.H {
419
- "logged_in" : b .auth .IsLoggedIn (c ),
420
- "is_admin" : b .auth .IsAdmin (c ),
421
- "version" : b .Version ,
422
- "title" : "Login Configuration Error" ,
423
- "recent" : b .GetLatest (),
421
+ "logged_in" : b .auth .IsLoggedIn (c ),
422
+ "is_admin" : b .auth .IsAdmin (c ),
423
+ "version" : b .Version ,
424
+ "title" : "Login Configuration Error" ,
425
+ "recent" : b .GetLatest (),
424
426
"admin_page" : false ,
425
427
})
426
428
return
@@ -429,12 +431,12 @@ func (b Blog) Login(c *gin.Context) {
429
431
430
432
clientID := os .Getenv ("client_id" )
431
433
c .HTML (http .StatusOK , "login.html" , gin.H {
432
- "logged_in" : b .auth .IsLoggedIn (c ),
433
- "is_admin" : b .auth .IsAdmin (c ),
434
- "client_id" : clientID ,
435
- "version" : b .Version ,
436
- "title" : "Login" ,
437
- "recent" : b .GetLatest (),
434
+ "logged_in" : b .auth .IsLoggedIn (c ),
435
+ "is_admin" : b .auth .IsAdmin (c ),
436
+ "client_id" : clientID ,
437
+ "version" : b .Version ,
438
+ "title" : "Login" ,
439
+ "recent" : b .GetLatest (),
438
440
"admin_page" : false ,
439
441
})
440
442
}
0 commit comments