From ee355dab674b5e61a3364555ce2c82c70508d233 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 21 Nov 2019 19:01:32 +0100 Subject: [PATCH 1/2] Add USE_SERVICE_WORKER setting This will be very useful setting for anyone doing frontend work. Fixes: https://github.com/go-gitea/gitea/issues/9044 --- custom/conf/app.ini.sample | 4 ++- .../doc/advanced/config-cheat-sheet.en-us.md | 5 ++-- .../doc/advanced/hacking-on-gitea.en-us.md | 8 +++-- modules/setting/setting.go | 2 ++ modules/templates/helper.go | 3 ++ templates/base/head.tmpl | 30 ++++++++++++------- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 599498a4b62c5..efe1013149055 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -153,6 +153,8 @@ THEMES = gitea,arc-green DEFAULT_SHOW_FULL_NAME = false ; Whether to search within description at repository search on explore page. SEARCH_REPO_DESCRIPTION = true +; Whether to enable a Service Worker to cache frontend assets +USE_SERVICE_WORKER = true [ui.admin] ; Number of users that are displayed on one page @@ -897,4 +899,4 @@ QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0" ; Max attempts per http/https request on migrations. MAX_ATTEMPTS = 3 ; Backoff time per http/https request retry (seconds) -RETRY_BACKOFF = 3 \ No newline at end of file +RETRY_BACKOFF = 3 diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 327efb34bd097..baa93a19b0524 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -118,8 +118,9 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install. - `THEMES`: **gitea,arc-green**: All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`. -- `DEFAULT_SHOW_FULL_NAME`: false: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. -- `SEARCH_REPO_DESCRIPTION`: true: Whether to search within description at repository search on explore page. +- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. +- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. +- `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets. ### UI - Admin (`ui.admin`) diff --git a/docs/content/doc/advanced/hacking-on-gitea.en-us.md b/docs/content/doc/advanced/hacking-on-gitea.en-us.md index 8c8249c0480e5..01e2474651e3a 100644 --- a/docs/content/doc/advanced/hacking-on-gitea.en-us.md +++ b/docs/content/doc/advanced/hacking-on-gitea.en-us.md @@ -138,9 +138,9 @@ make revive vet misspell-check ### Updating CSS -To generate the CSS, you will need [Node.js](https://nodejs.org/) 8.0 or greater with npm. At present we use [less](http://lesscss.org/) and [postcss](https://postcss.org) to generate our CSS. Do **not** edit the files in `public/css` directly, as they are generated from `lessc` from the files in `public/less`. +To generate the CSS, you need [Node.js](https://nodejs.org/) 8.0 or greater with npm. We use [less](http://lesscss.org/) and [postcss](https://postcss.org) to generate our CSS. Do **not** edit the files in `public/css` directly, as they are generated from `lessc` from the files in `public/less`. -Edit files in `public/less`, run the linter, regenerate the CSS and commit all changed files: +Edit files in `public/less`, and then run the linter and build the CSS files via: ```bash make css @@ -148,12 +148,14 @@ make css ### Updating JS -To run the JavaScript linter you will need [Node.js](https://nodejs.org/) 8.0 or greater with npm. Edit files in `public/js` and run the linter: +To generate the JS files, you need [Node.js](https://nodejs.org/) 8.0 or greater with npm. Edit files in `public/js`, run the linter and build the JS files via: ```bash make js ``` +Note: When working on frontend code, it is advisable to set `USE_SERVICE_WORKER` to `false` in `app.ini` which will prevent undesirable caching of frontend assets. + ### Updating the API When creating new API routes or modifying existing API routes, you **MUST** diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 6a45797cf2ebd..31bd9a8d8ea84 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -170,6 +170,7 @@ var ( DefaultTheme string Themes []string SearchRepoDescription bool + UseServiceWorker bool Admin struct { UserPagingNum int @@ -968,6 +969,7 @@ func NewContext() { UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true) UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true) + UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(true) HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt")) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 6aa429ee142c4..8b5497a1c9ac7 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -148,6 +148,9 @@ func NewFuncMap() []template.FuncMap { "MetaKeywords": func() string { return setting.UI.Meta.Keywords }, + "UseServiceWorker": func() bool { + return setting.UI.UseServiceWorker + }, "FilenameIsImage": func(filename string) bool { mimeType := mime.TypeByExtension(filepath.Ext(filename)) return strings.HasPrefix(mimeType, "image/") diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 32251f84ae734..52af5cdaa9817 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -7,20 +7,30 @@ {{if .Title}}{{.Title}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} + {{if UseServiceWorker}} + {{else}} + + {{end}} From 4863365db9734f8d21b1a09b1df3063f5b910527 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 21 Nov 2019 20:27:37 +0100 Subject: [PATCH 2/2] prevent potential syntax error on old browsers --- templates/base/head.tmpl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 52af5cdaa9817..2cc48c632fd2b 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -6,7 +6,6 @@ {{if .Title}}{{.Title}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} - {{if UseServiceWorker}} {{end}} -