Complete transformation to htmx

This commit is contained in:
Caleb Gardner
2024-11-01 04:00:55 -05:00
parent 6965917e76
commit 1061a38c6a
9 changed files with 215 additions and 127 deletions
+11
View File
@@ -3,6 +3,7 @@ package blog
import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
@@ -13,6 +14,12 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)
const authorInfo = `
<table><tr>
<td><img src="%v" alt="%v" class='author-pic'></td>
<td><h3 class="author-title">%v</h3>%v</td>
</tr></table>`
type Author struct {
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
@@ -20,6 +27,10 @@ type Author struct {
PicURL string `json:"picurl" bson:"picurl"`
}
func (a Author) HTML() string {
return fmt.Sprintf(authorInfo, a.PicURL, a.Name+"'s profile picture", a.Name, a.About)
}
func (b *BlogApp) AboutMe(ctx context.Context) (*Author, error) {
res := b.authCol.FindOne(ctx, bson.M{"_id": "caleb_gardner"})
if res.Err() != nil {