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