Added Open Graph tags to threads and posts
This commit is contained in:
parent
60b8016a1b
commit
61454b3e5b
21
pages/post/opengraph.go
Normal file
21
pages/post/opengraph.go
Normal 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
|
||||
}
|
@ -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
21
pages/thread/opengraph.go
Normal 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
|
||||
}
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user