diff --git a/modules/public/public.go b/modules/public/public.go
index 91ecf42a3cac5..e941fc078609e 100644
--- a/modules/public/public.go
+++ b/modules/public/public.go
@@ -23,8 +23,9 @@ type Options struct {
CorsHandler func(http.Handler) http.Handler
}
-// AssetsURLPathPrefix is the path prefix for static asset files
-const AssetsURLPathPrefix = "/assets/"
+// WebPublicDirName is the directory name for public(static) asset files. It may be set to the build time by `static.go`
+// the char `~` is not valid for user/repo names, so we do not need to reserve the names anymore.
+var WebPublicDirName = "public~dynamic"
// AssetsHandlerFunc implements the static handler for serving custom or original assets.
func AssetsHandlerFunc(opts *Options) http.HandlerFunc {
diff --git a/modules/public/static.go b/modules/public/static.go
index d373c712ee535..f24bf578aa3ed 100644
--- a/modules/public/static.go
+++ b/modules/public/static.go
@@ -10,6 +10,7 @@ package public
import (
"bytes"
"compress/gzip"
+ "fmt"
"io"
"mime"
"net/http"
@@ -18,12 +19,13 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/timeutil"
)
+var assetModTime time.Time
+
// GlobalModTime provide a global mod time for embedded asset files
func GlobalModTime(filename string) time.Time {
- return timeutil.GetExecutableModTime()
+ return assetModTime
}
func fileSystem(dir string) http.FileSystem {
@@ -91,3 +93,8 @@ func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modt
http.ServeContent(w, req, fi.Name(), modtime, content)
return
}
+
+func init() {
+ assetModTime = timeutil.GetExecutableModTime()
+ WebPublicDirName = fmt.Sprintf("public~%x", assetModTime.UnixMilli())
+}
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 255866e2ed1c6..17a2687cc1e54 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -33,6 +33,7 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
+ "code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/svg"
@@ -62,7 +63,7 @@ func NewFuncMap() []template.FuncMap {
return setting.AppSubURL
},
"AssetUrlPrefix": func() string {
- return setting.StaticURLPrefix + "/assets"
+ return setting.StaticURLPrefix + "/" + public.WebPublicDirName
},
"AppUrl": func() string {
return setting.AppURL
@@ -146,7 +147,6 @@ func NewFuncMap() []template.FuncMap {
"DiffLineTypeToStr": DiffLineTypeToStr,
"Sha1": Sha1,
"ShortSha": base.ShortSha,
- "MD5": base.EncodeMD5,
"ActionContent2Commits": ActionContent2Commits,
"PathEscape": url.PathEscape,
"PathEscapeSegments": util.PathEscapeSegments,
diff --git a/routers/install/routes.go b/routers/install/routes.go
index f377cd40c9a2b..fdf4651ca9aa3 100644
--- a/routers/install/routes.go
+++ b/routers/install/routes.go
@@ -85,9 +85,9 @@ func Routes() *web.Route {
r.Use(middle)
}
- r.Use(web.WrapWithPrefix(public.AssetsURLPathPrefix, public.AssetsHandlerFunc(&public.Options{
+ r.Use(web.WrapWithPrefix("/"+public.WebPublicDirName, public.AssetsHandlerFunc(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
- Prefix: public.AssetsURLPathPrefix,
+ Prefix: "/" + public.WebPublicDirName,
}), "InstallAssetsHandler"))
r.Use(session.Sessioner(session.Options{
diff --git a/routers/web/web.go b/routers/web/web.go
index 698f91b8cafa8..9c0f2239e047d 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -74,9 +74,9 @@ func CorsHandler() func(next http.Handler) http.Handler {
func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
routes := web.NewRoute()
- routes.Use(web.WrapWithPrefix(public.AssetsURLPathPrefix, public.AssetsHandlerFunc(&public.Options{
+ routes.Use(web.WrapWithPrefix("/"+public.WebPublicDirName, public.AssetsHandlerFunc(&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
- Prefix: public.AssetsURLPathPrefix,
+ Prefix: "/" + public.WebPublicDirName,
CorsHandler: CorsHandler(),
}), "AssetsHandler"))
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index 1aabfa2f5c644..a7c30f275c25f 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -22,7 +22,7 @@
{{end}}
{{end}}
-
+
{{template "custom/footer" .}}