xess.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Package xess vendors a copy of Xess and makes it available at /.xess/xess.css
  2. //
  3. // This is intended to be used as a vendored package in other projects.
  4. package xess
  5. import (
  6. "embed"
  7. "net/http"
  8. "path/filepath"
  9. "github.com/TecharoHQ/anubis"
  10. "github.com/TecharoHQ/anubis/internal"
  11. )
  12. var (
  13. //go:embed *.css static
  14. Static embed.FS
  15. BasePrefix = "/.within.website/x/xess/"
  16. URL = "/.within.website/x/xess/xess.css"
  17. )
  18. func init() {
  19. Mount(http.DefaultServeMux)
  20. //goland:noinspection GoBoolExpressions
  21. if anubis.Version != "devel" {
  22. URL = filepath.Join(filepath.Dir(URL), "xess.min.css")
  23. }
  24. URL = URL + "?cachebuster=" + anubis.Version
  25. }
  26. // Mount registers the xess static file handlers on the given mux
  27. func Mount(mux *http.ServeMux) {
  28. prefix := anubis.BasePrefix + "/.within.website/x/xess/"
  29. mux.Handle(prefix, internal.UnchangingCache(http.StripPrefix(prefix, http.FileServerFS(Static))))
  30. }