Fixed author name

This commit is contained in:
Caleb Gardner
2024-08-02 21:26:10 -05:00
parent 87ac3bf270
commit 7fe19eddc3
+9 -5
View File
@@ -11,10 +11,10 @@ import (
) )
const ( const (
blogTitle = "<h1 class='blog-title'>%v</h1>" blogTitle = "<h1 class='blog-title'><a href='%v'>%v</a></h1>"
blogAuthor = "<h4 class='blog-author'><i><b>By %v</b></i></h4>" blogAuthor = "<h4 class='blog-author'><i><b>By %v</b></i></h4>"
blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5" blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5"
blogMain = "<div class='blog'>%v</div>" blogMain = "<p class='blog'>%v</p>"
authorInfo = ` authorInfo = `
<table><tr> <table><tr>
@@ -60,8 +60,13 @@ func blogHandle(w http.ResponseWriter, blog string) {
} }
func blogElement(b *blog.Blog) (out string) { func blogElement(b *blog.Blog) (out string) {
out = fmt.Sprintf(blogTitle, b.Title) out = fmt.Sprintf(blogTitle, b.ID, b.Title)
out += fmt.Sprintf(blogAuthor, b.Author) auth, err := blogApp.GetAuthor(b)
if err == nil {
out += fmt.Sprintf(blogAuthor, auth.Name)
} else {
out += fmt.Sprintf(blogAuthor, "unknown")
}
cTime := time.Unix(b.CreateTime, 0).Format(time.DateOnly) cTime := time.Unix(b.CreateTime, 0).Format(time.DateOnly)
if b.UpdateTime > b.CreateTime { if b.UpdateTime > b.CreateTime {
out += fmt.Sprintf(blogCreate, cTime+"; Last updated on: "+time.Unix(b.UpdateTime, 0).Format(time.DateOnly)) out += fmt.Sprintf(blogCreate, cTime+"; Last updated on: "+time.Unix(b.UpdateTime, 0).Format(time.DateOnly))
@@ -69,7 +74,6 @@ func blogElement(b *blog.Blog) (out string) {
out += fmt.Sprintf(blogCreate, cTime) out += fmt.Sprintf(blogCreate, cTime)
} }
out += fmt.Sprintf(blogMain, b.Blog) out += fmt.Sprintf(blogMain, b.Blog)
auth, err := blogApp.GetAuthor(b)
if err == nil { if err == nil {
out += authorSection(auth) out += authorSection(auth)
} }