Add a logo
This commit is contained in:
parent
5339c442b7
commit
b1009fa109
18 changed files with 240 additions and 112 deletions
58
internal/dis/component/server/logo/logo.go
Normal file
58
internal/dis/component/server/logo/logo.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package logo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
type Logo struct {
|
||||
component.Base
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.Routeable = (*Logo)(nil)
|
||||
)
|
||||
|
||||
func (*Logo) Routes() component.Routes {
|
||||
return component.Routes{
|
||||
Prefix: "/logo/",
|
||||
Aliases: []string{"/favicon.ico", "/logo.svg"},
|
||||
Exact: true,
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
//go:embed favicon.ico
|
||||
faviconICO []byte
|
||||
|
||||
//go:embed logo.svg
|
||||
logoSVG []byte
|
||||
)
|
||||
|
||||
var faviconRoute = httpx.Response{
|
||||
ContentType: "image/x-icon",
|
||||
Body: faviconICO,
|
||||
}
|
||||
|
||||
var logoSVGRoute = httpx.Response{
|
||||
ContentType: "image/svg+xml",
|
||||
Body: httpx.MinifySVG(logoSVG),
|
||||
}
|
||||
|
||||
func (*Logo) HandleRoute(ctx context.Context, path string) (http.Handler, error) {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/favicon.ico":
|
||||
faviconRoute.ServeHTTP(w, r)
|
||||
case "/logo.svg":
|
||||
logoSVGRoute.ServeHTTP(w, r)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue