Created assets package

This commit is contained in:
Eduard Urbach 2019-05-23 15:02:13 +09:00
parent e722efa327
commit efc50eaf67
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
7 changed files with 61 additions and 66 deletions

View File

@ -1,55 +1,81 @@
package main
package assets
import (
"io/ioutil"
"strings"
"github.com/aerogo/aero"
"github.com/aerogo/manifest"
"github.com/aerogo/sitemap"
"github.com/akyoto/stringutils/unsafe"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components/css"
"github.com/animenotifier/notify.moe/components/js"
)
// configureAssets adds all the routes used for media assets.
func configureAssets(app *aero.Application) {
// Script bundle
scriptBundle := js.Bundle()
var (
Manifest *manifest.Manifest
JS string
CSS string
ServiceWorker string
Organization string
)
// load loads all the necessary assets into memory.
func load() {
var err error
// Manifest
Manifest, err = manifest.FromFile("manifest.json")
if err != nil {
panic("Couldn't load manifest.json")
}
// Service worker
serviceWorkerBytes, err := ioutil.ReadFile("scripts/ServiceWorker/ServiceWorker.js")
data, err := ioutil.ReadFile("scripts/ServiceWorker/ServiceWorker.js")
if err != nil {
panic("Couldn't load service worker")
}
serviceWorker := string(serviceWorkerBytes)
ServiceWorker = unsafe.BytesToString(data)
// CSS bundle
cssBundle := css.Bundle()
// Manifest
webManifest, err := manifest.FromFile("manifest.json")
// Organization
data, err = ioutil.ReadFile("organization.json")
if err != nil {
panic("Couldn't load web manifest")
panic("Couldn't load organization.json")
}
Organization = unsafe.BytesToString(data)
Organization = strings.ReplaceAll(Organization, "\n", "")
Organization = strings.ReplaceAll(Organization, "\t", "")
// Bundles
JS = js.Bundle()
CSS = css.Bundle()
}
// Configure adds all the routes used for media assets.
func Configure(app *aero.Application) {
load()
app.Get("/scripts", func(ctx *aero.Context) string {
return ctx.JavaScript(scriptBundle)
return ctx.JavaScript(JS)
})
app.Get("/styles", func(ctx *aero.Context) string {
return ctx.CSS(cssBundle)
return ctx.CSS(CSS)
})
app.Get("/service-worker", func(ctx *aero.Context) string {
return ctx.JavaScript(serviceWorker)
return ctx.JavaScript(ServiceWorker)
})
// Web manifest
app.Get("/manifest.json", func(ctx *aero.Context) string {
return ctx.JSON(webManifest)
return ctx.JSON(Manifest)
})
// Favicon

8
go.mod
View File

@ -6,7 +6,7 @@ require (
cloud.google.com/go v0.39.0 // indirect
github.com/OneOfOne/xxhash v1.2.5
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
github.com/aerogo/aero v1.1.17
github.com/aerogo/aero v1.2.1
github.com/aerogo/api v0.1.7
github.com/aerogo/crawler v0.2.5
github.com/aerogo/graphql v0.3.6
@ -22,8 +22,9 @@ require (
github.com/aerogo/sitemap v0.1.2
github.com/akyoto/cache v1.0.2
github.com/akyoto/color v1.8.4
github.com/akyoto/stringutils v0.2.0
github.com/animenotifier/anilist v0.2.3
github.com/animenotifier/arn v1.1.22
github.com/animenotifier/arn v1.1.23
github.com/animenotifier/kitsu v0.2.3
github.com/animenotifier/mal v0.2.3
github.com/animenotifier/shoboi v0.2.3
@ -37,7 +38,6 @@ require (
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
github.com/json-iterator/go v1.1.6
github.com/logpacker/PayPal-Go-SDK v1.1.4
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/minio/minio-go v6.0.14+incompatible
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mssola/user_agent v0.5.0
@ -47,10 +47,8 @@ require (
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/net v0.0.0-20190520210107-018c4d40a106 // indirect
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/appengine v1.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect

21
go.sum
View File

@ -19,10 +19,8 @@ github.com/aerogo/aero v1.1.9 h1:EB+oTljSIfQENZTVyvnZ24Pb2UsV+Ows04/HfzOJ/3c=
github.com/aerogo/aero v1.1.9/go.mod h1:MvHPJcXZmZUu5mh4q6j5n3DijKmAMY6puhzCH1w22Vw=
github.com/aerogo/aero v1.1.13 h1:e+FXHaSRZ2a/xrLwF1Yeujh5yHBovdLfHxJYtZvPpWw=
github.com/aerogo/aero v1.1.13/go.mod h1:jcHCf+a3vExpo1SKRPrmkspO9VWiDZHC5/ITss/Sz6Y=
github.com/aerogo/aero v1.1.15 h1:T+CYwhGi1OpFc2xZzCn8I/NKOcqvBtXVU+/+l1xEgfA=
github.com/aerogo/aero v1.1.15/go.mod h1:AqpqKoaoM/WuCmzbQl0Cl5IFkyRv7xPCfAc+oP10ur0=
github.com/aerogo/aero v1.1.17 h1:OgpdDSgY7FQ4iCZwzVRMsW3On0f7hSoyjV1yj5esoEQ=
github.com/aerogo/aero v1.1.17/go.mod h1:tXqLwzzZEsSJgKe7RgfvonPQ9CnYThLRLri2paUjSdE=
github.com/aerogo/aero v1.2.1 h1:oCDufiQua/URRWGs1cTAR8eroeRJSjakaS7zoTuI0Bc=
github.com/aerogo/aero v1.2.1/go.mod h1:NiTEzYsRlHY9vmzw9tKJqRiDh36LVVZba405l5HM0XE=
github.com/aerogo/api v0.1.7 h1:2cEOUlPvlRnLo6A0xn8+UpmluWqRoYEGn0Ik4kxmUEI=
github.com/aerogo/api v0.1.7/go.mod h1:6uPqLd2/VzFiuC7L7hPMtUNjfRjczJQUP6Uks7EiXpw=
github.com/aerogo/cluster v0.1.5 h1:mOYQmaYRsvIi1inaGLICmeJgCYycBxiHnjcTFLtC6kc=
@ -59,12 +57,6 @@ github.com/aerogo/linter-performance v1.0.3 h1:pYsmUd8jp6CVrFx+YNo9Gfdf222CKG2gC
github.com/aerogo/linter-performance v1.0.3/go.mod h1:po6XSSbSgR30lazzqSRGV++a2omxYr2qjqFvcvUCH40=
github.com/aerogo/log v0.2.5 h1:LGeElbLqyaD8r8Ls9HuG7tYF6YV4kP56IxJWl/b4cZQ=
github.com/aerogo/log v0.2.5/go.mod h1:8+dc8oT2gd4ftwf+u6WMKcjOfR6yzkcN+q3N6xg7VhI=
github.com/aerogo/manifest v0.1.1 h1:QhFKIvKTrZsqf1OnzQa1q5s0PDxWwevyG/35NQ82Nhc=
github.com/aerogo/manifest v0.1.1/go.mod h1:J8Dali+Ky2sktH1mG176b2picI3saJ3ZAmOWnz2+l8k=
github.com/aerogo/manifest v0.1.2 h1:LGTe7W3VHeyZaw18or/3JMnjvnGmnEmJdWpHRDzoCro=
github.com/aerogo/manifest v0.1.2/go.mod h1:3SvBzx0rCDNQ+C779aEj5ZyP0YWwdGPeEzsPM3VIOzg=
github.com/aerogo/manifest v0.1.3 h1:7SDWy/CNNnY7koppa2ZXkRe4vaUM6y4tEMxlxs8ghHw=
github.com/aerogo/manifest v0.1.3/go.mod h1:3SvBzx0rCDNQ+C779aEj5ZyP0YWwdGPeEzsPM3VIOzg=
github.com/aerogo/manifest v0.1.4 h1:JGRMJAANtgzhygMCMov6WgIRkiVuMgP3a+ossf//TJU=
github.com/aerogo/manifest v0.1.4/go.mod h1:3SvBzx0rCDNQ+C779aEj5ZyP0YWwdGPeEzsPM3VIOzg=
github.com/aerogo/markdown v0.1.8 h1:X/FlyuBqdVaFflggxDbXcqGCQNInLKwU/tvyNhg+mQw=
@ -131,8 +123,8 @@ github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRy
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/animenotifier/anilist v0.2.3 h1:409h1m4m59EBTQHc/F2U5PGY3lIWlvD/kRXxY1oTl5Q=
github.com/animenotifier/anilist v0.2.3/go.mod h1:WmivLHBTIs+zmqENjiVXH66laTYB8vT5d+8q1yzLX9I=
github.com/animenotifier/arn v1.1.22 h1:uSn+WkCYqlEQP4dfWVIIcqI0/gSrMLMwTmfYeHa7Unw=
github.com/animenotifier/arn v1.1.22/go.mod h1:/+2galtQdT775SVzT5D05bxTwYTrrXTomLB0QO8gEGI=
github.com/animenotifier/arn v1.1.23 h1:oirdOZ9R0CeNz642R0htwflS04+IN7dbkqx6XXIhoBM=
github.com/animenotifier/arn v1.1.23/go.mod h1:YYIhHYKafWGENlayhdoao2AmOAP3osUtgMxrkVfXx0w=
github.com/animenotifier/ffxiv v0.2.1 h1:gV5h47skizAWLJQb+M3CmExy1hlqDuKmNxkOpn3JwF0=
github.com/animenotifier/ffxiv v0.2.1/go.mod h1:9p0z9iQIT8nIlwH4xHUvdo0qFvJ4pVnFbBQ0G/JiY0k=
github.com/animenotifier/japanese v0.2.3 h1:fGX3CcX5lGzRC+JkokDCwJqRniPOmM44FLm7aqdnOEo=
@ -297,8 +289,8 @@ golang.org/x/net v0.0.0-20190509222800-a4d6f7feada5 h1:6M3SDHlHHDCx2PcQw3S4KsR17
golang.org/x/net v0.0.0-20190509222800-a4d6f7feada5/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190514140710-3ec191127204 h1:4yG6GqBtw9C+UrLp6s2wtSniayy/Vd/3F7ffLE427XI=
golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190520210107-018c4d40a106 h1:EZofHp/BzEf3j39/+7CX1JvH0WaPG+ikBrqAdAPf+GM=
golang.org/x/net v0.0.0-20190520210107-018c4d40a106/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 h1:XC1K3wNjuz44KaI+cj85C9TW85w/46RH7J+DTXNH5Wk=
@ -329,7 +321,6 @@ golang.org/x/sys v0.0.0-20190516014833-cab07311ab81/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190516102723-cedb8e16d18a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb h1:k07iPOt0d6nEnwXF+kHB+iEg+WSuKe/SOQuFM2QoD+E=
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190520201301-c432e742b0af/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5 h1:f005F/Jl5JLP036x7QIvUVhNTqxvSYwFIiyOh2q12iU=
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=

View File

@ -1,27 +1,14 @@
package fullpage
package layout
import (
"io/ioutil"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
jsoniter "github.com/json-iterator/go"
)
var organization map[string]interface{}
var organizationString string
func init() {
// Load structured data
organizationBytes, _ := ioutil.ReadFile("organization.json")
jsoniter.Unmarshal(organizationBytes, &organization)
organizationBytes, _ = jsoniter.Marshal(organization)
organizationString = string(organizationBytes)
}
// Render layout.
func Render(ctx *aero.Context, content string) string {
user := utils.GetUser(ctx)
@ -46,5 +33,5 @@ func Render(ctx *aero.Context, content string) string {
sort.Strings(tags)
}
return components.Layout(ctx.App, ctx, user, openGraph, meta, tags, organizationString, content)
return components.Layout(ctx, user, openGraph, meta, tags, content)
}

View File

@ -1,4 +1,4 @@
component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openGraph *arn.OpenGraph, meta, tags []string, organization string, content string)
component Layout(ctx *aero.Context, user *arn.User, openGraph *arn.OpenGraph, meta, tags []string, content string)
html(lang="en")
head
link(rel="stylesheet", href="/styles", importance="high")
@ -6,7 +6,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
if openGraph != nil
title= openGraph.Tags["og:title"]
else
title= app.Config.Title
title= ctx.App.Config.Title
//- Viewport
meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes")
@ -44,7 +44,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
//- Color of the embed sidebar in Discord,
//- also the color of tabs on mobile browsers.
meta(name="theme-color", content=app.Config.Manifest.ThemeColor)
meta(name="theme-color", content=assets.Manifest.ThemeColor)
//- Google site verification
meta(name="google-site-verification", content="1U-E2pDaYbFHyOSWl6AX3DvixQuDc4kfem9Kde_jZ8A")
@ -62,7 +62,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
#user(data-id=user.ID, data-pro=user.IsPro(), data-theme=user.Settings().Theme)
script(src="/scripts", importance="high", crossorigin="anonymous")
script(type="application/ld+json")!= organization
script(type="application/ld+json")!= assets.Organization
component Content(content string)
#content-container

View File

@ -6,6 +6,7 @@ import (
"github.com/aerogo/aero"
nanostore "github.com/aerogo/session-store-nano"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/assets"
"github.com/animenotifier/notify.moe/auth"
"github.com/animenotifier/notify.moe/graphql"
"github.com/animenotifier/notify.moe/middleware"
@ -32,7 +33,7 @@ func configure(app *aero.Application) *aero.Application {
configureHTTPS(app)
// Assets
configureAssets(app)
assets.Configure(app)
// Pages
pages.Configure(app)
@ -54,7 +55,7 @@ func configure(app *aero.Application) *aero.Application {
if arn.IsDevelopment() {
app.Config.Domain = "beta.notify.moe"
app.Config.Title += " - Beta"
app.Config.Manifest.Name = app.Config.Title
assets.Manifest.Name = app.Config.Title
}
// Authentication

View File

@ -5,8 +5,6 @@
"description":"Anime list, tracker, database and notifier for new anime episodes. Create your own anime list and keep track of your progress as you watch.",
"url":"https://notify.moe",
"email":"animenotifierofficial@gmail.com",
"telephone":"",
"faxNumber":"",
"logo":"https://media.notify.moe/images/brand/512.png",
"sameAs":[
"https://www.facebook.com/animenotifier",
@ -15,12 +13,6 @@
"https://discord.gg/0kimAmMCeXGXuzNF",
"https://github.com/animenotifier/notify.moe"
],
"address":{
"@type":"PostalAddress",
"addressLocality":"",
"postalCode":"",
"streetAddress":""
},
"founder":{
"@type":"Person",
"name":"Eduard Urbach"