diff options
author | silverwind <me@silverwind.io> | 2020-12-22 12:13:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 19:13:50 +0800 |
commit | 3a21f8a9865d1112d1b847fb20710e6b735174ec (patch) | |
tree | a0dd55fa92457fec77dabc6d3e83311ec3af8bb9 /modules | |
parent | cd607b5f98ccf66acd99a47309a3411a8e5c8993 (diff) | |
download | gitea-3a21f8a9865d1112d1b847fb20710e6b735174ec.tar.gz gitea-3a21f8a9865d1112d1b847fb20710e6b735174ec.zip |
Inline manifest.json (#14038)
* Inline manifest.json
Improve performance by eliminating this separate request and just inline
this small JSON in HTML directly as a data uri.
Also update previously static app name scripts to use AppName.
I've confirmed this as working via "Add to Homescreen" feature which
offered to save the shortcut under the new app name.
* prerender manifest data on startup
* move to settings
* restore setting.AppStartTime and use it on admin page
* use double quotes because template.URL escapes everything
* fix lint
* move variable to global context variable
* delete template file
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/context.go | 2 | ||||
-rw-r--r-- | modules/setting/setting.go | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index c6597cf024..2e43088ff8 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -345,6 +345,8 @@ func Contexter() macaron.Handler { ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations + ctx.Data["ManifestData"] = setting.ManifestData + c.Map(ctx) } } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 63ae15af97..290ec94c44 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -8,6 +8,7 @@ package setting import ( "encoding/base64" "fmt" + "html/template" "io" "io/ioutil" "math" @@ -293,6 +294,8 @@ var ( CSRFCookieName = "_csrf" CSRFCookieHTTPOnly = true + ManifestData template.URL + // Mirror settings Mirror struct { DefaultInterval time.Duration @@ -642,6 +645,8 @@ func NewContext() { LandingPageURL = LandingPageHome } + ManifestData = makeManifestData() + if len(SSH.Domain) == 0 { SSH.Domain = Domain } @@ -1040,6 +1045,14 @@ func loadOrGenerateInternalToken(sec *ini.Section) string { return token } +func makeManifestData() template.URL { + name := url.QueryEscape(AppName) + prefix := url.QueryEscape(StaticURLPrefix) + subURL := url.QueryEscape(AppSubURL) + "/" + + return template.URL(`data:application/json,{"short_name":"` + name + `","name":"` + name + `","icons":[{"src":"` + prefix + `/img/logo-lg.png","type":"image/png","sizes":"880x880"},{"src":"` + prefix + `/img/logo-sm.png","type":"image/png","sizes":"120x120"},{"src":"` + prefix + `/img/logo-512.png","type":"image/png","sizes":"512x512"},{"src":"` + prefix + `/img/logo-192.png","type":"image/png","sizes":"192x192"}],"start_url":"` + subURL + `","scope":"` + subURL + `","background_color":"%23FAFAFA","display":"standalone"}`) +} + // NewServices initializes the services func NewServices() { InitDBConfig() |