Deterministic output
This commit is contained in:
parent
423ad01af2
commit
454787b52d
@ -1,6 +1,8 @@
|
|||||||
package layout
|
package layout
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
@ -11,5 +13,25 @@ import (
|
|||||||
func Render(ctx *aero.Context, content string) string {
|
func Render(ctx *aero.Context, content string) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
openGraph, _ := ctx.Data.(*arn.OpenGraph)
|
openGraph, _ := ctx.Data.(*arn.OpenGraph)
|
||||||
return components.Layout(ctx.App, ctx, user, openGraph, content)
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
return components.Layout(ctx.App, ctx, user, openGraph, meta, tags, content)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openGraph *arn.OpenGraph, content string)
|
component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openGraph *arn.OpenGraph, meta, tags []string, content string)
|
||||||
html(lang="en")
|
html(lang="en")
|
||||||
head
|
head
|
||||||
if openGraph != nil
|
if openGraph != nil
|
||||||
@ -10,11 +10,11 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
|
|||||||
meta(name="theme-color", content=app.Config.Manifest.ThemeColor)
|
meta(name="theme-color", content=app.Config.Manifest.ThemeColor)
|
||||||
|
|
||||||
if openGraph != nil
|
if openGraph != nil
|
||||||
for name, value := range openGraph.Meta
|
for _, name := range meta
|
||||||
meta(name=name, content=value)
|
meta(name=name, content=openGraph.Meta[name])
|
||||||
|
|
||||||
for property, content := range openGraph.Tags
|
for _, name := range tags
|
||||||
meta(property=property, content=content)
|
meta(property=name, content=openGraph.Tags[name])
|
||||||
|
|
||||||
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user