Added Open Graph tags to threads and posts

This commit is contained in:
Eduard Urbach 2018-11-07 03:14:13 +09:00
parent 60b8016a1b
commit 61454b3e5b
4 changed files with 44 additions and 0 deletions

21
pages/post/opengraph.go Normal file
View File

@ -0,0 +1,21 @@
package post
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/utils"
)
func getOpenGraph(ctx *aero.Context, post *arn.Post) *arn.OpenGraph {
openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": post.TitleByUser(nil),
"og:description": utils.CutLongDescription(post.Text),
"og:url": "https://" + ctx.App.Config.Domain + post.Link(),
"og:site_name": ctx.App.Config.Domain,
"og:type": "article",
},
}
return openGraph
}

View File

@ -19,5 +19,6 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Post not found", err)
}
ctx.Data = getOpenGraph(ctx, post)
return ctx.HTML(components.Post(post, user))
}

21
pages/thread/opengraph.go Normal file
View File

@ -0,0 +1,21 @@
package thread
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/utils"
)
func getOpenGraph(ctx *aero.Context, thread *arn.Thread) *arn.OpenGraph {
openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": thread.Title,
"og:description": utils.CutLongDescription(thread.Text),
"og:url": "https://" + ctx.App.Config.Domain + thread.Link(),
"og:site_name": ctx.App.Config.Domain,
"og:type": "article",
},
}
return openGraph
}

View File

@ -21,5 +21,6 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Thread not found", err)
}
ctx.Data = getOpenGraph(ctx, thread)
return ctx.HTML(components.Thread(thread, user))
}