mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Pre-generate themes stylesheets at build time
This commit is contained in:
parent
459bb4531f
commit
ca30800e6a
3 changed files with 28 additions and 25 deletions
26
generate.go
26
generate.go
|
@ -116,23 +116,20 @@ func generateJSBundle(bundleFile string, srcFiles []string) {
|
||||||
bundle.Write(bundleFile)
|
bundle.Write(bundleFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateCSSBundle(bundleFile string, srcFiles []string) {
|
func generateCSSBundle(bundleFile string, themes map[string][]string) {
|
||||||
bundle := NewBundle("static", "Stylesheets")
|
bundle := NewBundle("static", "Stylesheets")
|
||||||
|
m := minify.New()
|
||||||
|
m.AddFunc("text/css", css.Minify)
|
||||||
|
|
||||||
for _, srcFile := range srcFiles {
|
for theme, srcFiles := range themes {
|
||||||
data := readFile(srcFile)
|
data := concat(srcFiles)
|
||||||
filename := stripExtension(basename(srcFile))
|
minifiedData, err := m.String("text/css", data)
|
||||||
|
|
||||||
m := minify.New()
|
|
||||||
m.AddFunc("text/css", css.Minify)
|
|
||||||
|
|
||||||
minifiedData, err := m.Bytes("text/css", data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle.Files[filename] = string(minifiedData)
|
bundle.Files[theme] = minifiedData
|
||||||
bundle.Checksums[filename] = checksum(minifiedData)
|
bundle.Checksums[theme] = checksum([]byte(minifiedData))
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle.Write(bundleFile)
|
bundle.Write(bundleFile)
|
||||||
|
@ -184,7 +181,12 @@ func main() {
|
||||||
"ui/static/js/bootstrap.js",
|
"ui/static/js/bootstrap.js",
|
||||||
})
|
})
|
||||||
|
|
||||||
generateCSSBundle("ui/static/css.go", glob("ui/static/css/*.css"))
|
generateCSSBundle("ui/static/css.go", map[string][]string{
|
||||||
|
"default": []string{"ui/static/css/common.css"},
|
||||||
|
"black": []string{"ui/static/css/common.css", "ui/static/css/black.css"},
|
||||||
|
"sansserif": []string{"ui/static/css/common.css", "ui/static/css/sansserif.css"},
|
||||||
|
})
|
||||||
|
|
||||||
generateBinaryBundle("ui/static/bin.go", glob("ui/static/bin/*"))
|
generateBinaryBundle("ui/static/bin.go", glob("ui/static/bin/*"))
|
||||||
|
|
||||||
generateBundle("sql/sql.go", "sql", "SqlMap", glob("sql/*.sql"))
|
generateBundle("sql/sql.go", "sql", "SqlMap", glob("sql/*.sql"))
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -10,19 +10,20 @@ import (
|
||||||
|
|
||||||
"github.com/miniflux/miniflux/http/request"
|
"github.com/miniflux/miniflux/http/request"
|
||||||
"github.com/miniflux/miniflux/http/response"
|
"github.com/miniflux/miniflux/http/response"
|
||||||
|
"github.com/miniflux/miniflux/http/response/html"
|
||||||
"github.com/miniflux/miniflux/ui/static"
|
"github.com/miniflux/miniflux/ui/static"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stylesheet renders the CSS.
|
// Stylesheet renders the CSS.
|
||||||
func (c *Controller) Stylesheet(w http.ResponseWriter, r *http.Request) {
|
func (c *Controller) Stylesheet(w http.ResponseWriter, r *http.Request) {
|
||||||
stylesheet := request.Param(r, "name", "white")
|
stylesheet := request.Param(r, "name", "default")
|
||||||
body := static.Stylesheets["common"]
|
if _, found := static.Stylesheets[stylesheet]; !found {
|
||||||
etag := static.StylesheetsChecksums["common"]
|
html.NotFound(w)
|
||||||
|
return
|
||||||
if theme, found := static.Stylesheets[stylesheet]; found {
|
|
||||||
body += theme
|
|
||||||
etag += static.StylesheetsChecksums[stylesheet]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body := static.Stylesheets[stylesheet]
|
||||||
|
etag := static.StylesheetsChecksums[stylesheet]
|
||||||
|
|
||||||
response.Cache(w, r, "text/css; charset=utf-8", etag, []byte(body), 48*time.Hour)
|
response.Cache(w, r, "text/css; charset=utf-8", etag, []byte(body), 48*time.Hour)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue