Skip to content

Commit 7e59ed8

Browse files
committed
Working using go-scholar with disk cache
1 parent 5072357 commit 7e59ed8

File tree

6 files changed

+146
-88
lines changed

6 files changed

+146
-88
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
articles.json
2+
profiles.json
3+
14
# Binaries for programs and plugins
25
*.exe
36
*.exe~

blog/blog.go

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type Blog struct {
2626
db *gorm.DB
2727
auth auth.IAuth
2828
Version string
29-
scholar scholar.Scholar
29+
scholar *scholar.Scholar
3030
}
3131

3232
// 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 {
3434
api := Blog{db, auth, version, scholar}
3535
return api
3636
}
@@ -174,20 +174,20 @@ func (b Blog) NoRoute(c *gin.Context) {
174174
if err == nil && post != nil {
175175
if b.auth.IsAdmin(c) {
176176
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(),
182182
"admin_page": false,
183183
})
184184
} else {
185185
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(),
191191
"admin_page": false,
192192
})
193193
}
@@ -207,7 +207,7 @@ func (b Blog) NoRoute(c *gin.Context) {
207207
"description": "The page at '" + c.Request.URL.String() + "' was not found",
208208
"version": b.Version,
209209
"recent": b.GetLatest(),
210-
"admin_page": false,
210+
"admin_page": false,
211211
})
212212
}
213213

@@ -216,24 +216,24 @@ func (b Blog) NoRoute(c *gin.Context) {
216216
// need to modify this function
217217
func (b Blog) Home(c *gin.Context) {
218218
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(),
224224
"admin_page": false,
225225
})
226226
}
227227

228228
// Posts is the index page for blog posts
229229
func (b Blog) Posts(c *gin.Context) {
230230
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(),
237237
"admin_page": false,
238238
})
239239
}
@@ -248,15 +248,15 @@ func (b Blog) Post(c *gin.Context) {
248248
"version": b.Version,
249249
"title": "Post Not Found",
250250
"recent": b.GetLatest(),
251-
"admin_page": false,
251+
"admin_page": false,
252252
})
253253
} else {
254254
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(),
260260
"admin_page": false,
261261
})
262262
//if b.auth.IsAdmin(c) {
@@ -288,17 +288,17 @@ func (b Blog) Tag(c *gin.Context) {
288288
"version": b.Version,
289289
"title": "Tag '" + tag + "' Not Found",
290290
"recent": b.GetLatest(),
291-
"admin_page": false,
291+
"admin_page": false,
292292
})
293293
} else {
294294
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(),
302302
"admin_page": false,
303303
})
304304
}
@@ -307,59 +307,61 @@ func (b Blog) Tag(c *gin.Context) {
307307
// Tags is the index page for all Tags
308308
func (b Blog) Tags(c *gin.Context) {
309309
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(),
314314
"admin_page": false,
315315
})
316316
}
317317

318318
// Speaking is the index page for presentations
319319
func (b Blog) Speaking(c *gin.Context) {
320320
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(),
326326
"admin_page": false,
327327
})
328328
}
329329

330330
// Speaking is the index page for research publications
331331
func (b Blog) Research(c *gin.Context) {
332+
articles := b.scholar.QueryProfileWithMemoryCache("SbUmSEAAAAAJ", 50)
333+
b.scholar.SaveCache("profiles.json", "articles.json")
332334
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,
339341
"admin_page": false,
340342
})
341343
}
342344

343345
// Projects is the index page for projects / code
344346
func (b Blog) Projects(c *gin.Context) {
345347
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(),
351353
"admin_page": false,
352354
})
353355
}
354356

355357
// About is the about page
356358
func (b Blog) About(c *gin.Context) {
357359
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(),
363365
"admin_page": false,
364366
})
365367
}
@@ -374,7 +376,7 @@ func (b Blog) Archives(c *gin.Context) {
374376
"byYear": b.getArchivesByYear(),
375377
"byYearMonth": b.getArchivesByYearMonth(),
376378
"recent": b.GetLatest(),
377-
"admin_page": false,
379+
"admin_page": false,
378380
})
379381
}
380382

@@ -416,11 +418,11 @@ func (b Blog) Login(c *gin.Context) {
416418
if err != nil {
417419
//todo: handle better - perhaps return error to browser
418420
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(),
424426
"admin_page": false,
425427
})
426428
return
@@ -429,12 +431,12 @@ func (b Blog) Login(c *gin.Context) {
429431

430432
clientID := os.Getenv("client_id")
431433
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(),
438440
"admin_page": false,
439441
})
440442
}

go.mod

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module goblog
22

3-
go 1.22.2
3+
go 1.23
4+
5+
toolchain go1.23.2
46

57
require (
6-
github.com/compscidr/scholar v1.0.4
8+
github.com/compscidr/scholar v1.0.5
79
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
810
github.com/gin-contrib/sessions v1.0.1
911
github.com/gin-contrib/static v1.1.2
@@ -17,7 +19,7 @@ require (
1719
)
1820

1921
require (
20-
github.com/PuerkitoBio/goquery v1.9.1 // indirect
22+
github.com/PuerkitoBio/goquery v1.10.0 // indirect
2123
github.com/andybalholm/cascadia v1.3.2 // indirect
2224
github.com/beevik/etree v1.1.0 // indirect
2325
github.com/bytedance/sonic v1.11.6 // indirect
@@ -45,19 +47,20 @@ require (
4547
github.com/kr/text v0.2.0 // indirect
4648
github.com/leodido/go-urn v1.4.0 // indirect
4749
github.com/mattn/go-isatty v0.0.20 // indirect
48-
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
50+
github.com/mattn/go-sqlite3 v1.14.24 // indirect
4951
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5052
github.com/modern-go/reflect2 v1.0.2 // indirect
53+
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect
5154
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
5255
github.com/pmezard/go-difflib v1.0.0 // indirect
5356
github.com/stretchr/objx v0.5.2 // indirect
5457
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5558
github.com/ugorji/go/codec v1.2.12 // indirect
5659
golang.org/x/arch v0.8.0 // indirect
57-
golang.org/x/crypto v0.23.0 // indirect
58-
golang.org/x/net v0.25.0 // indirect
59-
golang.org/x/sys v0.20.0 // indirect
60-
golang.org/x/text v0.15.0 // indirect
60+
golang.org/x/crypto v0.27.0 // indirect
61+
golang.org/x/net v0.29.0 // indirect
62+
golang.org/x/sys v0.25.0 // indirect
63+
golang.org/x/text v0.18.0 // indirect
6164
google.golang.org/protobuf v1.34.1 // indirect
6265
gopkg.in/yaml.v3 v3.0.1 // indirect
6366
)

0 commit comments

Comments
 (0)