mirror of
https://github.com/knadh/listmonk.git
synced 2024-09-20 07:16:33 +08:00
Add a ?v=hash
cache breaker (that changes on restart) to static assets.
This commit is contained in:
parent
a2629c2c31
commit
0c9dc07479
1
Makefile
1
Makefile
|
@ -13,6 +13,7 @@ FRONTEND_YARN_MODULES = frontend/node_modules
|
||||||
FRONTEND_DIST = frontend/dist
|
FRONTEND_DIST = frontend/dist
|
||||||
FRONTEND_DEPS = \
|
FRONTEND_DEPS = \
|
||||||
$(FRONTEND_YARN_MODULES) \
|
$(FRONTEND_YARN_MODULES) \
|
||||||
|
frontend/index.html \
|
||||||
frontend/package.json \
|
frontend/package.json \
|
||||||
frontend/vite.config.js \
|
frontend/vite.config.js \
|
||||||
frontend/.eslintrc.js \
|
frontend/.eslintrc.js \
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
@ -237,6 +238,8 @@ func handleAdminPage(c echo.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = bytes.ReplaceAll(b, []byte("asset_version"), []byte(app.constants.AssetVersion))
|
||||||
|
|
||||||
return c.HTMLBlob(http.StatusOK, b)
|
return c.HTMLBlob(http.StatusOK, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
@ -94,6 +95,7 @@ type constants struct {
|
||||||
OptinURL string
|
OptinURL string
|
||||||
MessageURL string
|
MessageURL string
|
||||||
ArchiveURL string
|
ArchiveURL string
|
||||||
|
AssetVersion string
|
||||||
|
|
||||||
MediaUpload struct {
|
MediaUpload struct {
|
||||||
Provider string
|
Provider string
|
||||||
|
@ -414,6 +416,9 @@ func initConstants() *constants {
|
||||||
c.BounceSendgridEnabled = ko.Bool("bounce.sendgrid_enabled")
|
c.BounceSendgridEnabled = ko.Bool("bounce.sendgrid_enabled")
|
||||||
c.BouncePostmarkEnabled = ko.Bool("bounce.postmark.enabled")
|
c.BouncePostmarkEnabled = ko.Bool("bounce.postmark.enabled")
|
||||||
|
|
||||||
|
b := md5.Sum([]byte(time.Now().String()))
|
||||||
|
c.AssetVersion = fmt.Sprintf("%x", b)[0:10]
|
||||||
|
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,6 +761,7 @@ func initHTTPServer(app *App) *echo.Echo {
|
||||||
RootURL: app.constants.RootURL,
|
RootURL: app.constants.RootURL,
|
||||||
LogoURL: app.constants.LogoURL,
|
LogoURL: app.constants.LogoURL,
|
||||||
FaviconURL: app.constants.FaviconURL,
|
FaviconURL: app.constants.FaviconURL,
|
||||||
|
AssetVersion: app.constants.AssetVersion,
|
||||||
EnablePublicSubPage: app.constants.EnablePublicSubPage,
|
EnablePublicSubPage: app.constants.EnablePublicSubPage,
|
||||||
EnablePublicArchive: app.constants.EnablePublicArchive,
|
EnablePublicArchive: app.constants.EnablePublicArchive,
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ type tplRenderer struct {
|
||||||
RootURL string
|
RootURL string
|
||||||
LogoURL string
|
LogoURL string
|
||||||
FaviconURL string
|
FaviconURL string
|
||||||
|
AssetVersion string
|
||||||
EnablePublicSubPage bool
|
EnablePublicSubPage bool
|
||||||
EnablePublicArchive bool
|
EnablePublicArchive bool
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,7 @@ type tplData struct {
|
||||||
RootURL string
|
RootURL string
|
||||||
LogoURL string
|
LogoURL string
|
||||||
FaviconURL string
|
FaviconURL string
|
||||||
|
AssetVersion string
|
||||||
EnablePublicSubPage bool
|
EnablePublicSubPage bool
|
||||||
EnablePublicArchive bool
|
EnablePublicArchive bool
|
||||||
Data interface{}
|
Data interface{}
|
||||||
|
@ -94,6 +96,7 @@ func (t *tplRenderer) Render(w io.Writer, name string, data interface{}, c echo.
|
||||||
RootURL: t.RootURL,
|
RootURL: t.RootURL,
|
||||||
LogoURL: t.LogoURL,
|
LogoURL: t.LogoURL,
|
||||||
FaviconURL: t.FaviconURL,
|
FaviconURL: t.FaviconURL,
|
||||||
|
AssetVersion: t.AssetVersion,
|
||||||
EnablePublicSubPage: t.EnablePublicSubPage,
|
EnablePublicSubPage: t.EnablePublicSubPage,
|
||||||
EnablePublicArchive: t.EnablePublicArchive,
|
EnablePublicArchive: t.EnablePublicArchive,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
|
6
frontend/index.html
vendored
6
frontend/index.html
vendored
|
@ -4,9 +4,9 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||||
<link rel="icon" href="/admin/static/favicon.png" />
|
<link rel="icon" href="/admin/static/favicon.png?v=asset_version" />
|
||||||
<link href="/admin/custom.css" rel="stylesheet" type="text/css">
|
<link href="/admin/custom.css?v=asset_version" rel="stylesheet" type="text/css">
|
||||||
<script src="/admin/custom.js" async defer></script>
|
<script src="/admin/custom.js?v=asset_version" async defer></script>
|
||||||
<title>listmonk</title>
|
<title>listmonk</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
href="{{ .RootURL }}/archive.xml" />
|
href="{{ .RootURL }}/archive.xml" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<link href="/public/static/style.css?v2.3.0" rel="stylesheet" type="text/css" />
|
<link href="/public/static/style.css?v={{ .AssetVersion }}" rel="stylesheet" type="text/css" />
|
||||||
<link href="/public/custom.css" rel="stylesheet" type="text/css">
|
<link href="/public/custom.css?v={{ .AssetVersion }}" rel="stylesheet" type="text/css">
|
||||||
<script src="/public/custom.js" async defer></script>
|
<script src="/public/custom.js?v={{ .AssetVersion }}" async defer></script>
|
||||||
|
|
||||||
{{ if ne .FaviconURL "" }}
|
{{ if ne .FaviconURL "" }}
|
||||||
<link rel="shortcut icon" href="{{ .FaviconURL }}" type="image/x-icon" />
|
<link rel="shortcut icon" href="{{ .FaviconURL }}" type="image/x-icon" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<link rel="shortcut icon" href="/public/static/favicon.png" type="image/x-icon" />
|
<link rel="shortcut icon" href="/public/static/favicon.png?v={{ .AssetVersion }}" type="image/x-icon" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
{{ if ne .LogoURL "" }}
|
{{ if ne .LogoURL "" }}
|
||||||
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /></a>
|
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /></a>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<img src="/public/static/logo.svg" alt="{{ .Data.Title }}" />
|
<img src="/public/static/logo.svg?v={{ .AssetVersion }}" alt="{{ .Data.Title }}" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue