static.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package controller
  5. import (
  6. "encoding/base64"
  7. "time"
  8. "github.com/miniflux/miniflux/logger"
  9. "github.com/miniflux/miniflux/server/core"
  10. "github.com/miniflux/miniflux/server/static"
  11. )
  12. // Stylesheet renders the CSS.
  13. func (c *Controller) Stylesheet(ctx *core.Context, request *core.Request, response *core.Response) {
  14. stylesheet := request.StringParam("name", "white")
  15. body := static.Stylesheets["common"]
  16. etag := static.StylesheetsChecksums["common"]
  17. if theme, found := static.Stylesheets[stylesheet]; found {
  18. body += theme
  19. etag += static.StylesheetsChecksums[stylesheet]
  20. }
  21. response.Cache("text/css; charset=utf-8", etag, []byte(body), 48*time.Hour)
  22. }
  23. // Javascript renders application client side code.
  24. func (c *Controller) Javascript(ctx *core.Context, request *core.Request, response *core.Response) {
  25. response.Cache("text/javascript; charset=utf-8", static.JavascriptChecksums["app"], []byte(static.Javascript["app"]), 48*time.Hour)
  26. }
  27. // Favicon renders the application favicon.
  28. func (c *Controller) Favicon(ctx *core.Context, request *core.Request, response *core.Response) {
  29. blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"])
  30. if err != nil {
  31. logger.Error("[Controller:Favicon] %v", err)
  32. response.HTML().NotFound()
  33. return
  34. }
  35. response.Cache("image/x-icon", static.BinariesChecksums["favicon.ico"], blob, 48*time.Hour)
  36. }