Skip to content

Commit b3c3dc7

Browse files
committed
Added latest post to footer
1 parent 9d04c2b commit b3c3dc7

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

blog/blog.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func (b Blog) GetPosts(drafts bool) []Post {
4444
return posts
4545
}
4646

47+
func (b Blog) GetLatest() Post {
48+
var post Post
49+
b.db.Preload("Tags").Order("created_at desc").First(&post)
50+
return post
51+
}
52+
4753
func (b Blog) getTags() []Tag {
4854
var tags []Tag
4955
b.db.Preload("Posts").Order("name asc").Find(&tags)
@@ -170,13 +176,15 @@ func (b Blog) NoRoute(c *gin.Context) {
170176
"is_admin": b.auth.IsAdmin(c),
171177
"post": post,
172178
"version": b.Version,
179+
"recent": b.GetLatest(),
173180
})
174181
} else {
175182
c.HTML(http.StatusOK, "post.html", gin.H{
176183
"logged_in": b.auth.IsLoggedIn(c),
177184
"is_admin": b.auth.IsAdmin(c),
178185
"post": post,
179186
"version": b.Version,
187+
"recent": b.GetLatest(),
180188
})
181189
}
182190
return
@@ -194,6 +202,7 @@ func (b Blog) NoRoute(c *gin.Context) {
194202
"error": "404: Page Not Found",
195203
"description": "The page at '" + c.Request.URL.String() + "' was not found",
196204
"version": b.Version,
205+
"recent": b.GetLatest(),
197206
})
198207
}
199208

@@ -206,6 +215,7 @@ func (b Blog) Home(c *gin.Context) {
206215
"is_admin": b.auth.IsAdmin(c),
207216
"version": b.Version,
208217
"title": "Software Engineer",
218+
"recent": b.GetLatest(),
209219
})
210220
}
211221

@@ -217,6 +227,7 @@ func (b Blog) Posts(c *gin.Context) {
217227
"posts": b.GetPosts(false),
218228
"version": b.Version,
219229
"title": "Posts",
230+
"recent": b.GetLatest(),
220231
})
221232
}
222233

@@ -229,13 +240,15 @@ func (b Blog) Post(c *gin.Context) {
229240
"description": err.Error(),
230241
"version": b.Version,
231242
"title": "Post Not Found",
243+
"recent": b.GetLatest(),
232244
})
233245
} else {
234246
c.HTML(http.StatusOK, "post.html", gin.H{
235247
"logged_in": b.auth.IsLoggedIn(c),
236248
"is_admin": b.auth.IsAdmin(c),
237249
"post": post,
238250
"version": b.Version,
251+
"recent": b.GetLatest(),
239252
})
240253
//if b.auth.IsAdmin(c) {
241254
// c.HTML(http.StatusOK, "post-admin.html", gin.H{
@@ -265,6 +278,7 @@ func (b Blog) Tag(c *gin.Context) {
265278
"description": err.Error(),
266279
"version": b.Version,
267280
"title": "Tag '" + tag + "' Not Found",
281+
"recent": b.GetLatest(),
268282
})
269283
} else {
270284
c.HTML(http.StatusOK, "tag.html", gin.H{
@@ -274,6 +288,7 @@ func (b Blog) Tag(c *gin.Context) {
274288
"tag": tag,
275289
"version": b.Version,
276290
"title": "Posts with Tag '" + tag + "'",
291+
"recent": b.GetLatest(),
277292
})
278293
}
279294
}
@@ -284,6 +299,7 @@ func (b Blog) Tags(c *gin.Context) {
284299
"version": b.Version,
285300
"title": "Tags",
286301
"tags": b.getTags(),
302+
"recent": b.GetLatest(),
287303
})
288304
}
289305

@@ -294,6 +310,7 @@ func (b Blog) Speaking(c *gin.Context) {
294310
"is_admin": b.auth.IsAdmin(c),
295311
"version": b.Version,
296312
"title": "Presentations and Speaking",
313+
"recent": b.GetLatest(),
297314
})
298315
}
299316

@@ -304,6 +321,7 @@ func (b Blog) Research(c *gin.Context) {
304321
"is_admin": b.auth.IsAdmin(c),
305322
"version": b.Version,
306323
"title": "Research Publications",
324+
"recent": b.GetLatest(),
307325
})
308326
}
309327

@@ -314,6 +332,7 @@ func (b Blog) Projects(c *gin.Context) {
314332
"is_admin": b.auth.IsAdmin(c),
315333
"version": b.Version,
316334
"title": "Projects",
335+
"recent": b.GetLatest(),
317336
})
318337
}
319338

@@ -324,6 +343,7 @@ func (b Blog) About(c *gin.Context) {
324343
"is_admin": b.auth.IsAdmin(c),
325344
"version": b.Version,
326345
"title": "About",
346+
"recent": b.GetLatest(),
327347
})
328348
}
329349

@@ -336,6 +356,7 @@ func (b Blog) Archives(c *gin.Context) {
336356
"title": "Blog Archives",
337357
"byYear": b.getArchivesByYear(),
338358
"byYearMonth": b.getArchivesByYearMonth(),
359+
"recent": b.GetLatest(),
339360
})
340361
}
341362

@@ -379,6 +400,7 @@ func (b Blog) Login(c *gin.Context) {
379400
"is_admin": b.auth.IsAdmin(c),
380401
"version": b.Version,
381402
"title": "Login Configuration Error",
403+
"recent": b.GetLatest(),
382404
})
383405
return
384406
}
@@ -391,6 +413,7 @@ func (b Blog) Login(c *gin.Context) {
391413
"client_id": clientID,
392414
"version": b.Version,
393415
"title": "Login",
416+
"recent": b.GetLatest(),
394417
})
395418
}
396419

templates/footer.html

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
</div> <!-- /footer -->
1414
<div class="spacer version">Powered by <a href="https://github.com/compscidr/goblog" target="goblog {{ .version }}">goblog {{ .version }}</a></div>
1515
</div>
16+
</div> <!-- / wrapper -->
17+
<div class="bottom bottom-0">
18+
<div class="container">
19+
<h2 class="pt-2">Most Recent Post</h2>
20+
<h3 class="text-left"><a href="{{ .recent.Permalink }}" title="{{ .recent.Title }}">{{ .recent.Title }}</a></h3>
21+
<p class="blog-post-meta text-left">{{ .recent.CreatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}
22+
{{ range .Tags }}
23+
<a href="{{ .recent.Permalink }}" title="{{ .recent.Name}}">#{{ .recent.Name }}</a>
24+
{{ end }}
25+
</p>
26+
<p class="text-justify">
27+
{{ .recent.PreviewContent 600 }} ...
28+
</p>
29+
</div>
30+
</div>
1631
<script>hljs.initHighlightingOnLoad();</script>
17-
<!-- Twitter universal website tag code -->
18-
<script>
19-
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
20-
},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='//static.ads-twitter.com/uwt.js',
21-
a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
22-
// Insert Twitter Pixel ID and Standard Event data below
23-
twq('init','o6m12');
24-
twq('track','PageView');
25-
</script>
26-
<!-- End Twitter universal website tag code -->
2732
</body>

templates/header.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@
104104
<a href="/login" title="Login">Login</a>
105105
{{ end }}
106106
</div>
107-
</div>
107+
</div>
108+
<div class="wrapper">

templates/research.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,6 @@ <h1>Research and Publications</h1>
223223
<br/>JB Ernst, SC Kremer, JJPC Rodrigues<br/>Physical Communication(13), 61-72 </div>
224224
<div class="col">2014</div>
225225
</div>
226-
226+
</div>
227227

228228
{{ template "footer.html" .}}

www/css/goblog.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
.profile { max-width:300px; margin-top: 30px; }
77
.footer { margin-top: 20px; }
88
html { height: 100%; }
9-
body { font-family: 'Source Code Pro', monospace; height: 100%; }
9+
body { font-family: 'Source Code Pro', monospace; min-height:100vh; display:flex; flex-direction:column; }
10+
.wrapper { flex: 1; }
1011
.menu a, .footer a { color: rgba(0,0,0,.70); }
1112
.footer a:hover { color: #007bff; }
1213
.logo { background: #777; color: #EEE; font-size: 28px; padding: 10px 15px 10px 15px; float:left; }
@@ -29,6 +30,8 @@ body { font-family: 'Source Code Pro', monospace; height: 100%; }
2930
.admin-posts li { padding-bottom: 10px; }
3031
.research { background:#EEEEEE; margin-bottom: 5px; padding:5px }
3132
.research:nth-child(even) { background: #FFFFFF; }
33+
.bottom { min-height: 200px; width: 100%; background-color: #333333; color: #EEE; }
34+
.bottom a { color: #EEE; }
3235
/* text animation */
3336
@keyframes animated-text{ from{width: 0;} to{width: 350px;} }
3437
/* cursor animations */

0 commit comments

Comments
 (0)