mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 11:21:19 +01:00
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>
This commit is contained in:
parent
cd607b5f98
commit
3a21f8a986
6 changed files with 17 additions and 46 deletions
|
@ -345,6 +345,8 @@ func Contexter() macaron.Handler {
|
||||||
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
|
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
|
||||||
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
||||||
|
|
||||||
|
ctx.Data["ManifestData"] = setting.ManifestData
|
||||||
|
|
||||||
c.Map(ctx)
|
c.Map(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package setting
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
|
@ -293,6 +294,8 @@ var (
|
||||||
CSRFCookieName = "_csrf"
|
CSRFCookieName = "_csrf"
|
||||||
CSRFCookieHTTPOnly = true
|
CSRFCookieHTTPOnly = true
|
||||||
|
|
||||||
|
ManifestData template.URL
|
||||||
|
|
||||||
// Mirror settings
|
// Mirror settings
|
||||||
Mirror struct {
|
Mirror struct {
|
||||||
DefaultInterval time.Duration
|
DefaultInterval time.Duration
|
||||||
|
@ -642,6 +645,8 @@ func NewContext() {
|
||||||
LandingPageURL = LandingPageHome
|
LandingPageURL = LandingPageHome
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ManifestData = makeManifestData()
|
||||||
|
|
||||||
if len(SSH.Domain) == 0 {
|
if len(SSH.Domain) == 0 {
|
||||||
SSH.Domain = Domain
|
SSH.Domain = Domain
|
||||||
}
|
}
|
||||||
|
@ -1040,6 +1045,14 @@ func loadOrGenerateInternalToken(sec *ini.Section) string {
|
||||||
return token
|
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
|
// NewServices initializes the services
|
||||||
func NewServices() {
|
func NewServices() {
|
||||||
InitDBConfig()
|
InitDBConfig()
|
||||||
|
|
|
@ -39,10 +39,6 @@ const (
|
||||||
tplQueue base.TplName = "admin/queue"
|
tplQueue base.TplName = "admin/queue"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
startTime = time.Now()
|
|
||||||
)
|
|
||||||
|
|
||||||
var sysStatus struct {
|
var sysStatus struct {
|
||||||
Uptime string
|
Uptime string
|
||||||
NumGoroutine int
|
NumGoroutine int
|
||||||
|
@ -85,7 +81,7 @@ var sysStatus struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSystemStatus() {
|
func updateSystemStatus() {
|
||||||
sysStatus.Uptime = timeutil.TimeSincePro(startTime, "en")
|
sysStatus.Uptime = timeutil.TimeSincePro(setting.AppStartTime, "en")
|
||||||
|
|
||||||
m := new(runtime.MemStats)
|
m := new(runtime.MemStats)
|
||||||
runtime.ReadMemStats(m)
|
runtime.ReadMemStats(m)
|
||||||
|
|
|
@ -6,12 +6,10 @@ package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/httpcache"
|
|
||||||
"code.gitea.io/gitea/modules/lfs"
|
"code.gitea.io/gitea/modules/lfs"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/options"
|
"code.gitea.io/gitea/modules/options"
|
||||||
|
@ -977,13 +975,6 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
|
||||||
private.RegisterRoutes(m)
|
private.RegisterRoutes(m)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Progressive Web App
|
|
||||||
m.Get("/manifest.json", templates.JSONRenderer(), func(ctx *context.Context) {
|
|
||||||
ctx.Resp.Header().Set("Cache-Control", httpcache.GetCacheControl())
|
|
||||||
ctx.Resp.Header().Set("Last-Modified", setting.AppStartTime.Format(http.TimeFormat))
|
|
||||||
ctx.HTML(200, "pwa/manifest_json")
|
|
||||||
})
|
|
||||||
|
|
||||||
// Not found handler.
|
// Not found handler.
|
||||||
m.NotFound(routers.NotFound)
|
m.NotFound(routers.NotFound)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
|
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
|
||||||
<link rel="manifest" href="{{AppSubUrl}}/manifest.json" crossorigin="use-credentials">
|
<link rel="manifest" href="{{.ManifestData}}"/>
|
||||||
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
|
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
|
||||||
<meta name="default-theme" content="{{DefaultTheme}}" />
|
<meta name="default-theme" content="{{DefaultTheme}}" />
|
||||||
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
|
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
{
|
|
||||||
"short_name": "Gitea",
|
|
||||||
"name": "Gitea - Git with a cup of tea",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "{{StaticUrlPrefix}}/img/logo-lg.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "880x880"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "{{StaticUrlPrefix}}/img/logo-sm.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "120x120"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "{{StaticUrlPrefix}}/img/logo-512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "{{StaticUrlPrefix}}/img/logo-192.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "192x192"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"start_url": "{{AppSubUrl}}/",
|
|
||||||
"scope": "{{AppSubUrl}}/",
|
|
||||||
"background_color": "#FAFAFA",
|
|
||||||
"display": "standalone",
|
|
||||||
"theme_color": "{{ThemeColorMetaTag}}"
|
|
||||||
}
|
|
Loading…
Reference in a new issue