From 19379802540f33c530357c6ca1db0a7bda7ed21b Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 6 Jul 2017 20:56:37 +0200 Subject: [PATCH] Improved OG data --- layout/layout.go | 5 +++-- layout/layout.pixy | 13 ++++++++----- pages/anime/anime.go | 23 ++++++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/layout/layout.go b/layout/layout.go index 4f449a21..384528a8 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -2,6 +2,7 @@ package layout import ( "github.com/aerogo/aero" + "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) @@ -9,6 +10,6 @@ import ( // Render layout. func Render(ctx *aero.Context, content string) string { user := utils.GetUser(ctx) - meta, _ := ctx.Data.(map[string]string) - return components.Layout(ctx.App, ctx, user, meta, content) + openGraph, _ := ctx.Data.(*arn.OpenGraph) + return components.Layout(ctx.App, ctx, user, openGraph, content) } diff --git a/layout/layout.pixy b/layout/layout.pixy index df520f62..09859ab4 100644 --- a/layout/layout.pixy +++ b/layout/layout.pixy @@ -1,14 +1,17 @@ -component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, meta map[string]string, content string) +component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openGraph *arn.OpenGraph, content string) html(lang="en") head title= app.Config.Title - + meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes") meta(name="theme-color", content=app.Config.Manifest.ThemeColor) - if meta != nil - for property, value := range meta - meta(name=property, value=value) + if openGraph != nil + for name, value := range openGraph.Meta + meta(name=name, content=value) + + for property, content := range openGraph.Tags + meta(property=property, content=content) link(rel="chrome-webstore-item", href="https://chrome.google.com/webstore/detail/hajchfikckiofgilinkpifobdbiajfch") link(rel="manifest", href="/manifest.json") diff --git a/pages/anime/anime.go b/pages/anime/anime.go index 1c4015f2..6c2ea54d 100644 --- a/pages/anime/anime.go +++ b/pages/anime/anime.go @@ -40,22 +40,27 @@ func Get(ctx *aero.Context) string { } // Open Graph - meta := map[string]string{ - "og:title": anime.Title.Canonical, - "og:image": anime.Image.Large, - "og:url": "https://" + ctx.App.Config.Domain + anime.Link(), - "og:site_name": "notify.moe", - "description": anime.Summary, + openGraph := &arn.OpenGraph{ + Tags: map[string]string{ + "og:title": anime.Title.Canonical, + "og:image": anime.Image.Large, + "og:url": "https://" + ctx.App.Config.Domain + anime.Link(), + "og:site_name": "notify.moe", + "og:description": anime.Summary, + }, + Meta: map[string]string{ + "description": anime.Summary, + }, } switch anime.Type { case "tv": - meta["og:type"] = "video.tv_show" + openGraph.Tags["og:type"] = "video.tv_show" case "movie": - meta["og:type"] = "video.movie" + openGraph.Tags["og:type"] = "video.movie" } - ctx.Data = meta + ctx.Data = openGraph return ctx.HTML(components.Anime(anime, tracks, user, episodesReversed)) }