55 lines
1.2 KiB
Go
Raw Normal View History

2017-11-18 11:28:53 +01:00
package company
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-11-18 11:46:17 +01:00
"github.com/animenotifier/notify.moe/utils"
2017-11-18 11:28:53 +01:00
)
const maxDescriptionLength = 170
2017-11-18 11:28:53 +01:00
// Get company.
func Get(ctx *aero.Context) string {
2017-11-18 11:46:17 +01:00
user := utils.GetUser(ctx)
2017-11-18 11:28:53 +01:00
id := ctx.Get("id")
company, err := arn.GetCompany(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Company not found", err)
}
description := company.Description
if len(description) > maxDescriptionLength {
description = description[:maxDescriptionLength-3] + "..."
}
2017-11-29 14:40:37 +01:00
openGraph := &arn.OpenGraph{
2017-11-19 00:34:03 +01:00
Tags: map[string]string{
"og:title": company.Name.English,
"og:url": "https://" + ctx.App.Config.Domain + company.Link(),
"og:site_name": "notify.moe",
"og:type": "article",
2017-11-19 00:34:03 +01:00
},
}
2017-11-29 14:40:37 +01:00
if company.Image != "" {
openGraph.Tags["og:image"] = company.Image
}
if description != "" {
openGraph.Tags["og:description"] = description
2017-11-29 14:44:02 +01:00
} else {
openGraph.Tags["og:description"] = company.Name.English + " company information."
}
2017-11-29 14:40:37 +01:00
ctx.Data = openGraph
2018-03-02 00:17:27 +01:00
studioAnime, producedAnime, licensedAnime := company.Anime()
return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, user))
2017-11-18 11:28:53 +01:00
}