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