Skip to content

Commit

Permalink
Inline manifest.json
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
silverwind committed Dec 21, 2020
1 parent addd424 commit 6d1adec
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 13 deletions.
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"runtime"
"strings"
"time"

"code.gitea.io/gitea/cmd"
"code.gitea.io/gitea/modules/log"
Expand Down Expand Up @@ -41,7 +40,6 @@ var (
func init() {
setting.AppVer = Version
setting.AppBuiltWith = formatBuiltWith()
setting.AppStartTime = time.Now().UTC()

// Grab the original help templates
originalAppHelpTemplate = cli.AppHelpTemplate
Expand Down
1 change: 0 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ var (
// AppVer settings
AppVer string
AppBuiltWith string
AppStartTime time.Time
AppName string
AppURL string
AppSubURL string
Expand Down
1 change: 1 addition & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func NewFuncMap() []template.FuncMap {
"MD5": base.EncodeMD5,
"ActionContent2Commits": ActionContent2Commits,
"PathEscape": url.PathEscape,
"QueryEscape": url.QueryEscape,
"EscapePound": func(str string) string {
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
},
Expand Down
9 changes: 0 additions & 9 deletions routers/routes/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ package routes

import (
"encoding/gob"
"net/http"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
Expand Down Expand Up @@ -977,13 +975,6 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
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.
m.NotFound(routers.NotFound)
}
2 changes: 1 addition & 1 deletion templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<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='data:application/json,{"short_name":"{{QueryEscape AppName}}","name":"{{QueryEscape AppName}}","icons":[{"src":"{{QueryEscape StaticUrlPrefix}}/img/logo-lg.png","type":"image/png","sizes":"880x880"},{"src":"{{QueryEscape StaticUrlPrefix}}/img/logo-sm.png","type":"image/png","sizes":"120x120"},{"src":"{{QueryEscape StaticUrlPrefix}}/img/logo-512.png","type":"image/png","sizes":"512x512"},{"src":"{{QueryEscape StaticUrlPrefix}}/img/logo-192.png","type":"image/png","sizes":"192x192"}],"start_url":"{{QueryEscape AppSubUrl}}/","scope":"{{QueryEscape AppSubUrl}}/","background_color":"%23FAFAFA","display":"standalone"}'/>
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
<meta name="default-theme" content="{{DefaultTheme}}" />
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
Expand Down

0 comments on commit 6d1adec

Please sign in to comment.