2017-11-11 14:09:30 +00:00
|
|
|
package fullpage
|
2017-06-15 21:03:55 +00:00
|
|
|
|
|
|
|
import (
|
2017-11-17 13:51:55 +00:00
|
|
|
"io/ioutil"
|
2017-11-09 07:45:51 +00:00
|
|
|
"sort"
|
|
|
|
|
2017-06-15 21:03:55 +00:00
|
|
|
"github.com/aerogo/aero"
|
2017-07-06 18:56:37 +00:00
|
|
|
"github.com/animenotifier/arn"
|
2017-06-15 21:03:55 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2018-07-02 00:39:25 +00:00
|
|
|
jsoniter "github.com/json-iterator/go"
|
2017-06-15 21:03:55 +00:00
|
|
|
)
|
|
|
|
|
2017-11-17 13:51:55 +00:00
|
|
|
var organization map[string]interface{}
|
|
|
|
var organizationString string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Load structured data
|
|
|
|
organizationBytes, _ := ioutil.ReadFile("organization.json")
|
2018-07-02 00:39:25 +00:00
|
|
|
jsoniter.Unmarshal(organizationBytes, &organization)
|
|
|
|
organizationBytes, _ = jsoniter.Marshal(organization)
|
2017-11-17 13:51:55 +00:00
|
|
|
organizationString = string(organizationBytes)
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:03:55 +00:00
|
|
|
// Render layout.
|
|
|
|
func Render(ctx *aero.Context, content string) string {
|
|
|
|
user := utils.GetUser(ctx)
|
2017-07-06 18:56:37 +00:00
|
|
|
openGraph, _ := ctx.Data.(*arn.OpenGraph)
|
2017-11-09 07:45:51 +00:00
|
|
|
|
|
|
|
// Make output order deterministic to profit from Aero caching.
|
|
|
|
// To do this, we need to create slices and sort the tags.
|
|
|
|
var meta []string
|
|
|
|
var tags []string
|
|
|
|
|
|
|
|
if openGraph != nil {
|
|
|
|
for name := range openGraph.Meta {
|
|
|
|
meta = append(meta, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(meta)
|
|
|
|
|
|
|
|
for name := range openGraph.Tags {
|
|
|
|
tags = append(tags, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(tags)
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:51:55 +00:00
|
|
|
return components.Layout(ctx.App, ctx, user, openGraph, meta, tags, organizationString, content)
|
2017-06-15 21:03:55 +00:00
|
|
|
}
|