Skip to content

Commit

Permalink
added og data
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Aug 24, 2023
1 parent 7d0f8fa commit dbb0278
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
18 changes: 12 additions & 6 deletions handlers/blogHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type BlogPage struct {
Blog *Blog
MyEmail string
IsAdmin bool
SiteData *SiteData
}

// AddBlogPageData AddBlogPageData
Expand Down Expand Up @@ -117,7 +118,7 @@ func (h *MCHandler) GetBlogList(w http.ResponseWriter, r *http.Request) {
bb.TextHTML = template.HTML(bb.Blog.Content)
h.Log.Debug("TextHTML: ", bb.TextHTML)
}

wg.Add(1)
go func(bbb *Blog) {
defer wg.Done()
Expand Down Expand Up @@ -151,13 +152,12 @@ func (h *MCHandler) GetBlogList(w http.ResponseWriter, r *http.Request) {
}(&bb)

wg.Wait()


blst = append(blst, bb)
}
bp.BlogList = &blst
h.Log.Debug("after all waits")

h.Templates.ExecuteTemplate(w, blogListPage, &bp)
} else {
http.Redirect(w, r, loginRt, http.StatusFound)
Expand All @@ -184,7 +184,6 @@ func (h *MCHandler) AddBlogPage(w http.ResponseWriter, r *http.Request) {
pd.UserEmail = uemail.(string)
}


h.Templates.ExecuteTemplate(w, addBlogPage, &pd)
} else {
http.Redirect(w, r, indexRt, http.StatusFound)
Expand Down Expand Up @@ -236,10 +235,19 @@ func (h *MCHandler) GetBlog(w http.ResponseWriter, r *http.Request) {
var wg sync.WaitGroup
bg := h.Delegate.GetBlog(bid)

var sd SiteData
sd.Canonical = template.URL(h.SiteURL + "/viewPost/" + bidstr)
sd.OgURL = template.URL(h.SiteURL + "/viewPost/" + bidstr)
sd.OgSiteName = h.SiteName
sd.OgType = "article"
//sd.Description = bg.Name
sd.OgTitle = bg.Name

var bp BlogPage
bp.Title = h.Title
bp.Desc = h.Desc
bp.KeyWords = h.KeyWords
bp.SiteData = &sd
uemail := s.Get("userEmail")
if uemail != nil {
bp.MyEmail = uemail.(string)
Expand Down Expand Up @@ -289,8 +297,6 @@ func (h *MCHandler) GetBlog(w http.ResponseWriter, r *http.Request) {
h.Log.Debug("User Done: ")
}(&bb)



wg.Wait()

h.Templates.ExecuteTemplate(w, blogPage, &bp)
Expand Down
13 changes: 13 additions & 0 deletions handlers/mcHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ import (
s "github.com/Ulbora/go-micro-blog-ui/signins"
)

// SiteData SiteData
type SiteData struct {
Canonical template.URL
OgImage template.URL
OgType string
OgSiteName string
OgTitle string
OgURL template.URL
Description string
}

// MCHandler MCHandler
type MCHandler struct {
Log lg.Log
Expand All @@ -42,9 +53,11 @@ type MCHandler struct {
Templates *template.Template

//page attributes
SiteName string
Title string
Desc string
KeyWords string
SiteURL string
}

// New New
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func main() {
var restURL string
var apiKey string
var apiAdminKey string
var siteURL string
var siteName string
// var linkedInSigninRedirectURL string
// var googleSigninRedirectURL string

Expand Down Expand Up @@ -86,6 +88,18 @@ func main() {
apiAdminKey = "54211789991515"
}

if os.Getenv("SITE_URL") != "" {
siteURL = os.Getenv("SITE_URL")
} else {
siteURL = "http://localhost:8080"
}

if os.Getenv("SITE_NAME") != "" {
siteName = os.Getenv("SITE_NAME")
} else {
siteName = "Go Micro Blog"
}

var l lg.Logger
log := l.New()
log.SetLogLevel(lg.AllLevel)
Expand All @@ -110,9 +124,11 @@ func main() {
dd := del.New()

var sh hd.MCHandler
sh.SiteName = siteName
sh.Title = siteTitle
sh.Desc = siteDesc
sh.KeyWords = siteKeyWords
sh.SiteURL = siteURL
sh.Log = log
sh.SessionManager = sessionManager
sh.Delegate = dd
Expand Down
7 changes: 7 additions & 0 deletions static/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<meta name="description" content="{{.Desc}}">
<meta name="keywords" content="{{.KeyWords}}">
<meta name="author" content="">
{{if .SiteData}}
<meta property="og:type" content="{{.SiteData.OgType}}">
<meta property="og:site_name" content="{{.SiteData.OgSiteName}}">
<meta property="og:title" content="{{.SiteData.OgTitle}}">
<meta property="og:url" content="{{.SiteData.OgURL}}">
<link rel="canonical" href="{{.SiteData.Canonical}}">
{{end}}
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap core CSS -->
<!-- <link href="../css/bootstrap.min.css" rel="stylesheet"> -->
Expand Down

0 comments on commit dbb0278

Please sign in to comment.