Skip to content

Commit

Permalink
Added latest post to footer
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Jul 28, 2023
1 parent 9d04c2b commit b3c3dc7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
23 changes: 23 additions & 0 deletions blog/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func (b Blog) GetPosts(drafts bool) []Post {
return posts
}

func (b Blog) GetLatest() Post {
var post Post
b.db.Preload("Tags").Order("created_at desc").First(&post)
return post
}

func (b Blog) getTags() []Tag {
var tags []Tag
b.db.Preload("Posts").Order("name asc").Find(&tags)
Expand Down Expand Up @@ -170,13 +176,15 @@ func (b Blog) NoRoute(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"post": post,
"version": b.Version,
"recent": b.GetLatest(),
})
} else {
c.HTML(http.StatusOK, "post.html", gin.H{
"logged_in": b.auth.IsLoggedIn(c),
"is_admin": b.auth.IsAdmin(c),
"post": post,
"version": b.Version,
"recent": b.GetLatest(),
})
}
return
Expand All @@ -194,6 +202,7 @@ func (b Blog) NoRoute(c *gin.Context) {
"error": "404: Page Not Found",
"description": "The page at '" + c.Request.URL.String() + "' was not found",
"version": b.Version,
"recent": b.GetLatest(),
})
}

Expand All @@ -206,6 +215,7 @@ func (b Blog) Home(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "Software Engineer",
"recent": b.GetLatest(),
})
}

Expand All @@ -217,6 +227,7 @@ func (b Blog) Posts(c *gin.Context) {
"posts": b.GetPosts(false),
"version": b.Version,
"title": "Posts",
"recent": b.GetLatest(),
})
}

Expand All @@ -229,13 +240,15 @@ func (b Blog) Post(c *gin.Context) {
"description": err.Error(),
"version": b.Version,
"title": "Post Not Found",
"recent": b.GetLatest(),
})
} else {
c.HTML(http.StatusOK, "post.html", gin.H{
"logged_in": b.auth.IsLoggedIn(c),
"is_admin": b.auth.IsAdmin(c),
"post": post,
"version": b.Version,
"recent": b.GetLatest(),
})
//if b.auth.IsAdmin(c) {
// c.HTML(http.StatusOK, "post-admin.html", gin.H{
Expand Down Expand Up @@ -265,6 +278,7 @@ func (b Blog) Tag(c *gin.Context) {
"description": err.Error(),
"version": b.Version,
"title": "Tag '" + tag + "' Not Found",
"recent": b.GetLatest(),
})
} else {
c.HTML(http.StatusOK, "tag.html", gin.H{
Expand All @@ -274,6 +288,7 @@ func (b Blog) Tag(c *gin.Context) {
"tag": tag,
"version": b.Version,
"title": "Posts with Tag '" + tag + "'",
"recent": b.GetLatest(),
})
}
}
Expand All @@ -284,6 +299,7 @@ func (b Blog) Tags(c *gin.Context) {
"version": b.Version,
"title": "Tags",
"tags": b.getTags(),
"recent": b.GetLatest(),
})
}

Expand All @@ -294,6 +310,7 @@ func (b Blog) Speaking(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "Presentations and Speaking",
"recent": b.GetLatest(),
})
}

Expand All @@ -304,6 +321,7 @@ func (b Blog) Research(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "Research Publications",
"recent": b.GetLatest(),
})
}

Expand All @@ -314,6 +332,7 @@ func (b Blog) Projects(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "Projects",
"recent": b.GetLatest(),
})
}

Expand All @@ -324,6 +343,7 @@ func (b Blog) About(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "About",
"recent": b.GetLatest(),
})
}

Expand All @@ -336,6 +356,7 @@ func (b Blog) Archives(c *gin.Context) {
"title": "Blog Archives",
"byYear": b.getArchivesByYear(),
"byYearMonth": b.getArchivesByYearMonth(),
"recent": b.GetLatest(),
})
}

Expand Down Expand Up @@ -379,6 +400,7 @@ func (b Blog) Login(c *gin.Context) {
"is_admin": b.auth.IsAdmin(c),
"version": b.Version,
"title": "Login Configuration Error",
"recent": b.GetLatest(),
})
return
}
Expand All @@ -391,6 +413,7 @@ func (b Blog) Login(c *gin.Context) {
"client_id": clientID,
"version": b.Version,
"title": "Login",
"recent": b.GetLatest(),
})
}

Expand Down
25 changes: 15 additions & 10 deletions templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
</div> <!-- /footer -->
<div class="spacer version">Powered by <a href="https://github.com/compscidr/goblog" target="goblog {{ .version }}">goblog {{ .version }}</a></div>
</div>
</div> <!-- / wrapper -->
<div class="bottom bottom-0">
<div class="container">
<h2 class="pt-2">Most Recent Post</h2>
<h3 class="text-left"><a href="{{ .recent.Permalink }}" title="{{ .recent.Title }}">{{ .recent.Title }}</a></h3>
<p class="blog-post-meta text-left">{{ .recent.CreatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}
{{ range .Tags }}
<a href="{{ .recent.Permalink }}" title="{{ .recent.Name}}">#{{ .recent.Name }}</a>
{{ end }}
</p>
<p class="text-justify">
{{ .recent.PreviewContent 600 }} ...
</p>
</div>
</div>
<script>hljs.initHighlightingOnLoad();</script>
<!-- Twitter universal website tag code -->
<script>
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='//static.ads-twitter.com/uwt.js',
a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
// Insert Twitter Pixel ID and Standard Event data below
twq('init','o6m12');
twq('track','PageView');
</script>
<!-- End Twitter universal website tag code -->
</body>
3 changes: 2 additions & 1 deletion templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@
<a href="/login" title="Login">Login</a>
{{ end }}
</div>
</div>
</div>
<div class="wrapper">
2 changes: 1 addition & 1 deletion templates/research.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,6 @@ <h1>Research and Publications</h1>
<br/>JB Ernst, SC Kremer, JJPC Rodrigues<br/>Physical Communication(13), 61-72 </div>
<div class="col">2014</div>
</div>

</div>

{{ template "footer.html" .}}
5 changes: 4 additions & 1 deletion www/css/goblog.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
.profile { max-width:300px; margin-top: 30px; }
.footer { margin-top: 20px; }
html { height: 100%; }
body { font-family: 'Source Code Pro', monospace; height: 100%; }
body { font-family: 'Source Code Pro', monospace; min-height:100vh; display:flex; flex-direction:column; }
.wrapper { flex: 1; }
.menu a, .footer a { color: rgba(0,0,0,.70); }
.footer a:hover { color: #007bff; }
.logo { background: #777; color: #EEE; font-size: 28px; padding: 10px 15px 10px 15px; float:left; }
Expand All @@ -29,6 +30,8 @@ body { font-family: 'Source Code Pro', monospace; height: 100%; }
.admin-posts li { padding-bottom: 10px; }
.research { background:#EEEEEE; margin-bottom: 5px; padding:5px }
.research:nth-child(even) { background: #FFFFFF; }
.bottom { min-height: 200px; width: 100%; background-color: #333333; color: #EEE; }
.bottom a { color: #EEE; }
/* text animation */
@keyframes animated-text{ from{width: 0;} to{width: 350px;} }
/* cursor animations */
Expand Down

0 comments on commit b3c3dc7

Please sign in to comment.