Improved OG data

This commit is contained in:
Eduard Urbach 2017-07-06 20:56:37 +02:00
parent 0e009f434c
commit 1937980254
3 changed files with 25 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package layout
import ( import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )
@ -9,6 +10,6 @@ import (
// Render layout. // Render layout.
func Render(ctx *aero.Context, content string) string { func Render(ctx *aero.Context, content string) string {
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
meta, _ := ctx.Data.(map[string]string) openGraph, _ := ctx.Data.(*arn.OpenGraph)
return components.Layout(ctx.App, ctx, user, meta, content) return components.Layout(ctx.App, ctx, user, openGraph, content)
} }

View File

@ -1,4 +1,4 @@
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") html(lang="en")
head head
title= app.Config.Title title= app.Config.Title
@ -6,9 +6,12 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, meta
meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes") 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) meta(name="theme-color", content=app.Config.Manifest.ThemeColor)
if meta != nil if openGraph != nil
for property, value := range meta for name, value := range openGraph.Meta
meta(name=property, value=value) 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="chrome-webstore-item", href="https://chrome.google.com/webstore/detail/hajchfikckiofgilinkpifobdbiajfch")
link(rel="manifest", href="/manifest.json") link(rel="manifest", href="/manifest.json")

View File

@ -40,22 +40,27 @@ func Get(ctx *aero.Context) string {
} }
// Open Graph // Open Graph
meta := map[string]string{ openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": anime.Title.Canonical, "og:title": anime.Title.Canonical,
"og:image": anime.Image.Large, "og:image": anime.Image.Large,
"og:url": "https://" + ctx.App.Config.Domain + anime.Link(), "og:url": "https://" + ctx.App.Config.Domain + anime.Link(),
"og:site_name": "notify.moe", "og:site_name": "notify.moe",
"og:description": anime.Summary,
},
Meta: map[string]string{
"description": anime.Summary, "description": anime.Summary,
},
} }
switch anime.Type { switch anime.Type {
case "tv": case "tv":
meta["og:type"] = "video.tv_show" openGraph.Tags["og:type"] = "video.tv_show"
case "movie": 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)) return ctx.HTML(components.Anime(anime, tracks, user, episodesReversed))
} }