Improved OpenGraph tags
This commit is contained in:
parent
ca020a9faa
commit
50b800971e
@ -19,6 +19,9 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
|
||||
//- This is equal to link-color in the styles.
|
||||
meta(name="theme-color", content="#d7260f")
|
||||
|
||||
//- Facebook App ID
|
||||
meta(property="fb:app_id", content="915407915202908")
|
||||
|
||||
for _, name := range meta
|
||||
meta(name=name, content=openGraph.Meta[name])
|
||||
|
||||
|
@ -19,5 +19,6 @@ func Get(ctx *aero.Context) string {
|
||||
return ctx.Error(http.StatusNotFound, "AMV not found", err)
|
||||
}
|
||||
|
||||
ctx.Data = getOpenGraph(ctx, amv)
|
||||
return ctx.HTML(components.AMVPage(amv, user))
|
||||
}
|
||||
|
42
pages/amv/opengraph.go
Normal file
42
pages/amv/opengraph.go
Normal file
@ -0,0 +1,42 @@
|
||||
package amv
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
func getOpenGraph(ctx *aero.Context, amv *arn.AMV) *arn.OpenGraph {
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
"og:title": amv.Title.ByUser(nil) + " (AMV)",
|
||||
"og:url": "https://" + ctx.App.Config.Domain + amv.Link(),
|
||||
"og:site_name": ctx.App.Config.Domain,
|
||||
"og:type": "video.other",
|
||||
},
|
||||
Meta: map[string]string{},
|
||||
}
|
||||
|
||||
if amv.MainAnime() != nil {
|
||||
openGraph.Tags["og:image"] = amv.MainAnime().ImageLink("large")
|
||||
openGraph.Tags["og:description"] = amv.MainAnime().Title.Canonical + " (" + strings.Join(amv.Tags, ", ") + ")"
|
||||
} else {
|
||||
openGraph.Tags["og:description"] = strings.Join(amv.Tags, ", ")
|
||||
}
|
||||
|
||||
if amv.File != "" {
|
||||
openGraph.Tags["og:video"] = "https://" + ctx.App.Config.Domain + "/videos/amvs/" + amv.File
|
||||
openGraph.Tags["og:video:type"] = "video/webm"
|
||||
openGraph.Tags["og:video:width"] = "640"
|
||||
openGraph.Tags["og:video:height"] = "360"
|
||||
|
||||
openGraph.Meta["twitter:player"] = openGraph.Tags["og:video"]
|
||||
openGraph.Meta["twitter:player:width"] = openGraph.Tags["og:video:width"]
|
||||
openGraph.Meta["twitter:player:height"] = openGraph.Tags["og:video:height"]
|
||||
openGraph.Meta["twitter:player:stream"] = openGraph.Tags["og:video"]
|
||||
openGraph.Meta["twitter:player:stream:content_type"] = openGraph.Tags["og:video:type"]
|
||||
}
|
||||
|
||||
return openGraph
|
||||
}
|
48
pages/soundtrack/opengraph.go
Normal file
48
pages/soundtrack/opengraph.go
Normal file
@ -0,0 +1,48 @@
|
||||
package soundtrack
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
func getOpenGraph(ctx *aero.Context, track *arn.SoundTrack) *arn.OpenGraph {
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
"og:title": track.Title.ByUser(nil),
|
||||
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
|
||||
"og:site_name": ctx.App.Config.Domain,
|
||||
"og:type": "music.song",
|
||||
},
|
||||
}
|
||||
|
||||
descriptionTags := []string{}
|
||||
|
||||
for _, tag := range track.Tags {
|
||||
if strings.HasPrefix(tag, "anime:") {
|
||||
continue
|
||||
}
|
||||
|
||||
descriptionTags = append(descriptionTags, tag)
|
||||
}
|
||||
|
||||
if track.MainAnime() != nil {
|
||||
openGraph.Tags["og:image"] = track.MainAnime().ImageLink("large")
|
||||
openGraph.Tags["og:description"] = track.MainAnime().Title.Canonical + " (" + strings.Join(descriptionTags, ", ") + ")"
|
||||
}
|
||||
|
||||
if track.File != "" {
|
||||
openGraph.Tags["og:audio"] = "https://" + ctx.App.Config.Domain + "/audio/" + track.File
|
||||
openGraph.Tags["og:audio:type"] = "audio/vnd.facebook.bridge"
|
||||
}
|
||||
|
||||
// Set video so that it can be played
|
||||
youtube := track.MediaByService("Youtube")
|
||||
|
||||
if len(youtube) > 0 {
|
||||
openGraph.Tags["og:video"] = "https://www.youtube.com/v/" + youtube[0].ServiceID
|
||||
}
|
||||
|
||||
return openGraph
|
||||
}
|
@ -2,7 +2,6 @@ package soundtrack
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -23,43 +22,3 @@ func Get(ctx *aero.Context) string {
|
||||
ctx.Data = getOpenGraph(ctx, track)
|
||||
return ctx.HTML(components.SoundTrackPage(track, user))
|
||||
}
|
||||
|
||||
func getOpenGraph(ctx *aero.Context, track *arn.SoundTrack) *arn.OpenGraph {
|
||||
openGraph := &arn.OpenGraph{
|
||||
Tags: map[string]string{
|
||||
"og:title": track.Title.ByUser(nil),
|
||||
"og:url": "https://" + ctx.App.Config.Domain + track.Link(),
|
||||
"og:site_name": ctx.App.Config.Domain,
|
||||
"og:type": "music.song",
|
||||
},
|
||||
}
|
||||
|
||||
descriptionTags := []string{}
|
||||
|
||||
for _, tag := range track.Tags {
|
||||
if strings.HasPrefix(tag, "anime:") {
|
||||
continue
|
||||
}
|
||||
|
||||
descriptionTags = append(descriptionTags, tag)
|
||||
}
|
||||
|
||||
if track.MainAnime() != nil {
|
||||
openGraph.Tags["og:image"] = track.MainAnime().ImageLink("large")
|
||||
openGraph.Tags["og:description"] = track.MainAnime().Title.Canonical + " (" + strings.Join(descriptionTags, ", ") + ")"
|
||||
}
|
||||
|
||||
if track.File != "" {
|
||||
openGraph.Tags["og:audio"] = "https://" + ctx.App.Config.Domain + "/audio/" + track.File
|
||||
openGraph.Tags["og:audio:type"] = "audio/vnd.facebook.bridge"
|
||||
}
|
||||
|
||||
// Set video so that it can be played
|
||||
youtube := track.MediaByService("Youtube")
|
||||
|
||||
if len(youtube) > 0 {
|
||||
openGraph.Tags["og:video"] = "https://www.youtube.com/v/" + youtube[0].ServiceID
|
||||
}
|
||||
|
||||
return openGraph
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user