44 lines
1.1 KiB
Go
Raw Normal View History

2017-12-03 21:33:24 +00:00
package quote
import (
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2019-06-01 04:55:49 +00:00
"github.com/animenotifier/notify.moe/assets"
2017-12-03 21:33:24 +00:00
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/server/middleware"
2017-12-03 21:33:24 +00:00
)
2018-02-24 12:11:12 +00:00
// Get quote.
2019-06-01 04:55:49 +00:00
func Get(ctx aero.Context) error {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2017-12-03 21:33:24 +00:00
id := ctx.Get("id")
quote, err := arn.GetQuote(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Quote not found", err)
}
openGraph := &arn.OpenGraph{
Tags: map[string]string{
2018-02-25 11:19:27 +00:00
"og:title": "Quote",
2018-02-25 18:22:59 +00:00
"og:description": quote.Text.English,
2019-06-01 04:55:49 +00:00
"og:url": "https://" + assets.Domain + quote.Link(),
2017-12-03 21:33:24 +00:00
"og:site_name": "notify.moe",
"og:type": "article",
},
}
2018-02-25 11:19:27 +00:00
character, _ := arn.GetCharacter(quote.CharacterID)
if character != nil {
2018-03-27 03:25:25 +00:00
openGraph.Tags["og:title"] = character.Name.Canonical + "'s quote"
openGraph.Tags["og:image"] = "https:" + character.ImageLink("large")
2018-02-25 11:19:27 +00:00
}
2019-06-01 04:55:49 +00:00
customCtx := ctx.(*middleware.OpenGraphContext)
customCtx.OpenGraph = openGraph
2017-12-03 21:33:24 +00:00
return ctx.HTML(components.QuotePage(quote, character, user))
}