From 454787b52d031523975220ed3f7e3619b3c75164 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 9 Nov 2017 08:45:51 +0100 Subject: [PATCH] Deterministic output --- layout/layout.go | 24 +++++++++++++++++++++++- layout/layout.pixy | 16 ++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/layout/layout.go b/layout/layout.go index 384528a8..2d38d112 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -1,6 +1,8 @@ package layout import ( + "sort" + "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" @@ -11,5 +13,25 @@ import ( func Render(ctx *aero.Context, content string) string { user := utils.GetUser(ctx) 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) } diff --git a/layout/layout.pixy b/layout/layout.pixy index d63fa6d9..808a79a8 100644 --- a/layout/layout.pixy +++ b/layout/layout.pixy @@ -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") head if openGraph != nil @@ -8,14 +8,14 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes") meta(name="theme-color", content=app.Config.Manifest.ThemeColor) - + if openGraph != nil - for name, value := range openGraph.Meta - meta(name=name, content=value) - - for property, content := range openGraph.Tags - meta(property=property, content=content) - + for _, name := range meta + meta(name=name, content=openGraph.Meta[name]) + + for _, name := range tags + meta(property=name, content=openGraph.Tags[name]) + link(rel="chrome-webstore-item", href="https://chrome.google.com/webstore/detail/hajchfikckiofgilinkpifobdbiajfch") link(rel="manifest", href="/manifest.json") body