mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-23 04:52:40 +00:00
Add custom logo configuration (#209)
This commit is contained in:
parent
7f4be43bb4
commit
afbecd9a1e
6 changed files with 50 additions and 13 deletions
|
@ -90,3 +90,9 @@ oidc.client-key:
|
||||||
oidc.secret:
|
oidc.secret:
|
||||||
# Discovery endpoint of the OpenID provider. Generally something like http://auth.example.com/.well-known/openid-configuration
|
# Discovery endpoint of the OpenID provider. Generally something like http://auth.example.com/.well-known/openid-configuration
|
||||||
oidc.discovery-url:
|
oidc.discovery-url:
|
||||||
|
|
||||||
|
|
||||||
|
# Custom assets
|
||||||
|
# Add your own custom assets to $opengist-home/custom/
|
||||||
|
custom.logo:
|
||||||
|
custom.favicon:
|
||||||
|
|
|
@ -30,3 +30,5 @@
|
||||||
| oidc.client-key | OG_OIDC_CLIENT_KEY | none | The client key for the OpenID application. |
|
| oidc.client-key | OG_OIDC_CLIENT_KEY | none | The client key for the OpenID application. |
|
||||||
| oidc.secret | OG_OIDC_SECRET | none | The secret for the OpenID application. |
|
| oidc.secret | OG_OIDC_SECRET | none | The secret for the OpenID application. |
|
||||||
| oidc.discovery-url | OG_OIDC_DISCOVERY_URL | none | Discovery endpoint of the OpenID provider. |
|
| oidc.discovery-url | OG_OIDC_DISCOVERY_URL | none | Discovery endpoint of the OpenID provider. |
|
||||||
|
| custom.logo | OG_CUSTOM_LOGO | none | Path to an image, relative to $opengist-home/custom |
|
||||||
|
| custom.favicon | OG_CUSTOM_FAVICON | none | Path to an image, relative to $opengist-home/custom |
|
||||||
|
|
|
@ -60,6 +60,9 @@ type config struct {
|
||||||
OIDCClientKey string `yaml:"oidc.client-key" env:"OG_OIDC_CLIENT_KEY"`
|
OIDCClientKey string `yaml:"oidc.client-key" env:"OG_OIDC_CLIENT_KEY"`
|
||||||
OIDCSecret string `yaml:"oidc.secret" env:"OG_OIDC_SECRET"`
|
OIDCSecret string `yaml:"oidc.secret" env:"OG_OIDC_SECRET"`
|
||||||
OIDCDiscoveryUrl string `yaml:"oidc.discovery-url" env:"OG_OIDC_DISCOVERY_URL"`
|
OIDCDiscoveryUrl string `yaml:"oidc.discovery-url" env:"OG_OIDC_DISCOVERY_URL"`
|
||||||
|
|
||||||
|
CustomLogo string `yaml:"custom.logo" env:"OG_CUSTOM_LOGO"`
|
||||||
|
CustomFavicon string `yaml:"custom.favicon" env:"OG_CUSTOM_FAVICON"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func configWithDefaults() (*config, error) {
|
func configWithDefaults() (*config, error) {
|
||||||
|
|
|
@ -10,6 +10,9 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -88,7 +91,8 @@ var (
|
||||||
|
|
||||||
return defaultAvatar()
|
return defaultAvatar()
|
||||||
},
|
},
|
||||||
"asset": asset,
|
"asset": asset,
|
||||||
|
"custom": customAsset,
|
||||||
"dev": func() bool {
|
"dev": func() bool {
|
||||||
return dev
|
return dev
|
||||||
},
|
},
|
||||||
|
@ -205,8 +209,15 @@ func NewServer(isDev bool) *Server {
|
||||||
|
|
||||||
if !dev {
|
if !dev {
|
||||||
parseManifestEntries()
|
parseManifestEntries()
|
||||||
e.GET("/assets/*", cacheControl(echo.WrapHandler(http.FileServer(http.FS(public.Files)))))
|
|
||||||
}
|
}
|
||||||
|
customFs := os.DirFS(filepath.Join(config.GetHomeDir(), "custom"))
|
||||||
|
e.GET("/assets/*", func(c echo.Context) error {
|
||||||
|
if _, err := public.Files.Open(path.Join("assets", c.Param("*"))); !dev && err == nil {
|
||||||
|
return echo.WrapHandler(http.FileServer(http.FS(public.Files)))(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return echo.WrapHandler(http.StripPrefix("/assets/", http.FileServer(http.FS(customFs))))(c)
|
||||||
|
})
|
||||||
|
|
||||||
// Web based routes
|
// Web based routes
|
||||||
g1 := e.Group("")
|
g1 := e.Group("")
|
||||||
|
@ -466,13 +477,6 @@ func checkRequireLogin(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cacheControl(next echo.HandlerFunc) echo.HandlerFunc {
|
|
||||||
return func(c echo.Context) error {
|
|
||||||
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000")
|
|
||||||
return next(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func noRouteFound(echo.Context) error {
|
func noRouteFound(echo.Context) error {
|
||||||
return notFound("Page not found")
|
return notFound("Page not found")
|
||||||
}
|
}
|
||||||
|
@ -512,3 +516,11 @@ func asset(file string) string {
|
||||||
}
|
}
|
||||||
return config.C.ExternalUrl + "/" + manifestEntries[file].File
|
return config.C.ExternalUrl + "/" + manifestEntries[file].File
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func customAsset(file string) string {
|
||||||
|
assetpath, err := url.JoinPath("/", "assets", file)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msgf("Failed to join path for custom file %s", file)
|
||||||
|
}
|
||||||
|
return config.C.ExternalUrl + assetpath
|
||||||
|
}
|
||||||
|
|
|
@ -51,7 +51,9 @@ func initialize() {
|
||||||
if err := os.MkdirAll(filepath.Join(homePath, "tmp", "repos"), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Join(homePath, "tmp", "repos"), 0755); err != nil {
|
||||||
log.Fatal().Err(err).Send()
|
log.Fatal().Err(err).Send()
|
||||||
}
|
}
|
||||||
|
if err := os.MkdirAll(filepath.Join(homePath, "custom"), 0755); err != nil {
|
||||||
|
log.Fatal().Err(err).Send()
|
||||||
|
}
|
||||||
log.Info().Msg("Database file: " + filepath.Join(homePath, config.C.DBFilename))
|
log.Info().Msg("Database file: " + filepath.Join(homePath, config.C.DBFilename))
|
||||||
if err := db.Setup(filepath.Join(homePath, config.C.DBFilename), false); err != nil {
|
if err := db.Setup(filepath.Join(homePath, config.C.DBFilename), false); err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to initialize database")
|
log.Fatal().Err(err).Msg("Failed to initialize database")
|
||||||
|
|
18
templates/base/base_header.html
vendored
18
templates/base/base_header.html
vendored
|
@ -28,7 +28,11 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset "favicon-32.png" }}">
|
{{ if $.c.CustomFavicon }}
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="{{ custom $.c.CustomFavicon }}">
|
||||||
|
{{ else }}
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset "favicon-32.png" }}">
|
||||||
|
{{ end }}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
{{ if dev }}
|
{{ if dev }}
|
||||||
|
@ -66,13 +70,21 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-shrink-0 items-center hidden sm:flex">
|
<div class="flex-shrink-0 items-center hidden sm:flex">
|
||||||
<a href="{{ $.c.ExternalUrl }}/">
|
<a href="{{ $.c.ExternalUrl }}/">
|
||||||
<img src="{{ asset "opengist.svg" }}" class="object-cover h-12 w-12">
|
{{ if $.c.CustomLogo }}
|
||||||
|
<img src="{{ custom $.c.CustomLogo }}" class="object-cover h-12">
|
||||||
|
{{ else }}
|
||||||
|
<img src="{{ asset "opengist.svg" }}" class="object-cover h-12 w-12">
|
||||||
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 flex items-center justify-center sm:items-stretch sm:justify-start">
|
<div class="flex-1 flex items-center justify-center sm:items-stretch sm:justify-start">
|
||||||
<div class="flex-shrink-0 items-center flex sm:hidden">
|
<div class="flex-shrink-0 items-center flex sm:hidden">
|
||||||
<a href="{{ $.c.ExternalUrl }}/">
|
<a href="{{ $.c.ExternalUrl }}/">
|
||||||
<img src="{{ asset "opengist.svg" }}" class="object-cover h-12 w-12">
|
{{ if $.c.CustomLogo }}
|
||||||
|
<img src="{{ custom $.c.CustomLogo }}" class="object-cover h-12">
|
||||||
|
{{ else }}
|
||||||
|
<img src="{{ asset "opengist.svg" }}" class="object-cover h-12 w-12">
|
||||||
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden sm:block sm:ml-6">
|
<div class="hidden sm:block sm:ml-6">
|
||||||
|
|
Loading…
Reference in a new issue