Skip to content

Commit b9e3801

Browse files
committed
add /assets as root dir of public files
Signed-off-by: a1012112796 <[email protected]>
1 parent 9d57373 commit b9e3801

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

models/user.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"code.gitea.io/gitea/modules/generate"
2626
"code.gitea.io/gitea/modules/git"
2727
"code.gitea.io/gitea/modules/log"
28-
"code.gitea.io/gitea/modules/public"
2928
"code.gitea.io/gitea/modules/setting"
3029
"code.gitea.io/gitea/modules/storage"
3130
"code.gitea.io/gitea/modules/structs"
@@ -780,7 +779,7 @@ func (u *User) IsGhost() bool {
780779
}
781780

782781
var (
783-
reservedUsernames = append([]string{
782+
reservedUsernames = []string{
784783
".",
785784
"..",
786785
".well-known",
@@ -815,7 +814,9 @@ var (
815814
"stars",
816815
"template",
817816
"user",
818-
}, public.KnownPublicEntries...)
817+
"favicon.ico",
818+
"serviceworker.js",
819+
}
819820

820821
reservedUserPatterns = []string{"*.keys", "*.gpg"}
821822
)

modules/public/public.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ var KnownPublicEntries = []string{
3232
"js",
3333
"serviceworker.js",
3434
"vendor",
35-
"favicon.ico",
3635
}
3736

3837
// Custom implements the static handler for serving custom assets.

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,12 +1144,12 @@ func MakeManifestData(appName string, appURL string, absoluteAssetURL string) []
11441144
StartURL: appURL,
11451145
Icons: []manifestIcon{
11461146
{
1147-
Src: absoluteAssetURL + "/img/logo.png",
1147+
Src: absoluteAssetURL + "/assets/img/logo.png",
11481148
Type: "image/png",
11491149
Sizes: "512x512",
11501150
},
11511151
{
1152-
Src: absoluteAssetURL + "/img/logo.svg",
1152+
Src: absoluteAssetURL + "/assets/img/logo.svg",
11531153
Type: "image/svg+xml",
11541154
Sizes: "512x512",
11551155
},

modules/templates/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewFuncMap() []template.FuncMap {
6161
return setting.AppSubURL
6262
},
6363
"StaticUrlPrefix": func() string {
64-
return setting.StaticURLPrefix
64+
return setting.StaticURLPrefix + "/assets"
6565
},
6666
"AppUrl": func() string {
6767
return setting.AppURL

routers/routes/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func WebRoutes() *web.Route {
152152
&public.Options{
153153
Directory: path.Join(setting.StaticRootPath, "public"),
154154
SkipLogging: setting.DisableRouterLog,
155+
Prefix: "/assets",
155156
},
156157
))
157158

routers/user/profile.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ func GetUserByParams(ctx *context.Context) *models.User {
4444
// Profile render user's profile page
4545
func Profile(ctx *context.Context) {
4646
uname := ctx.Params(":username")
47-
// Special handle for FireFox requests favicon.ico.
47+
48+
// Special handle for requests `favicon.ico` and `serviceworker.js`.
4849
if uname == "favicon.ico" {
4950
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
5051
return
51-
} else if strings.HasSuffix(uname, ".png") {
52+
}
53+
54+
if uname == "serviceworker.js" {
55+
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/serviceworker.js"))
56+
return
57+
}
58+
59+
if strings.HasSuffix(uname, ".png") {
5260
ctx.Error(404)
5361
return
5462
}

0 commit comments

Comments
 (0)