mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-27 17:51:23 +00:00
feat: show version in footer
This commit is contained in:
parent
77d1cfbc81
commit
cf1d26100b
5 changed files with 24 additions and 17 deletions
|
@ -73,7 +73,7 @@ func main() {
|
|||
if startServer {
|
||||
slog.Info("Setting up Server")
|
||||
cfg := config.NewServerConfig()
|
||||
server, err := server.NewServer(cfg)
|
||||
server, err := server.NewServer(version, cfg)
|
||||
if err != nil {
|
||||
slog.Error("Unable to create server", "error", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -14,18 +14,20 @@ import (
|
|||
)
|
||||
|
||||
type Server struct {
|
||||
echo *echo.Echo
|
||||
cfg *config.ServerConfig
|
||||
logger *slog.Logger
|
||||
echo *echo.Echo
|
||||
cfg *config.ServerConfig
|
||||
logger *slog.Logger
|
||||
version string
|
||||
|
||||
worker *Worker
|
||||
}
|
||||
|
||||
func NewServer(cfg *config.ServerConfig) (*Server, error) {
|
||||
func NewServer(version string, cfg *config.ServerConfig) (*Server, error) {
|
||||
return &Server{
|
||||
cfg: cfg,
|
||||
echo: echo.New(),
|
||||
logger: slog.Default(),
|
||||
cfg: cfg,
|
||||
echo: echo.New(),
|
||||
logger: slog.Default(),
|
||||
version: version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -51,7 +53,7 @@ func (s *Server) Start() error {
|
|||
|
||||
s.worker = NewWorker(temporalClient, s.cfg, s.logger, sqliteDb, kvStore)
|
||||
|
||||
templates, err := templates.NewTemplates(s.logger)
|
||||
templates, err := templates.NewTemplates(s.version, s.logger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create templates")
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
func NewServer(l *slog.Logger, cfg *config.Config, tokenKeyProvider authorization.TokenKeyProvider) (t.Server, error) {
|
||||
logger := slogLogger{
|
||||
log: l,
|
||||
level: slog.LevelDebug,
|
||||
level: slog.LevelInfo,
|
||||
}
|
||||
|
||||
sqlConfig := cfg.Persistence.DataStores[PersistenceStoreName].SQL
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
{{ template "main" . }}
|
||||
<div class="container mx-auto">
|
||||
<footer class="text-center text-gray-600 text-xs mt-8 mb-4">
|
||||
<a class="hover:underline" href="https://zdravko.mnts.dev">Zdravko</a>
|
||||
<a class="hover:underline" href="https://zdravko.mnts.dev"
|
||||
>Zdravko {{ Version }}</a
|
||||
>
|
||||
-
|
||||
<a
|
||||
class="hover:underline"
|
||||
|
|
|
@ -23,7 +23,7 @@ type Templates struct {
|
|||
templates map[string]*template.Template
|
||||
}
|
||||
|
||||
func load(files ...string) *template.Template {
|
||||
func load(version string, files ...string) *template.Template {
|
||||
files = append(files, base)
|
||||
|
||||
t := template.New("default").Funcs(
|
||||
|
@ -44,17 +44,20 @@ func load(files ...string) *template.Template {
|
|||
"Now": time.Now,
|
||||
"ScriptUnescapeString": script.UnescapeString,
|
||||
"ScriptEscapeString": script.EscapeString,
|
||||
"Version": func() string {
|
||||
return version
|
||||
},
|
||||
})
|
||||
|
||||
return template.Must(t.ParseFS(templates, files...))
|
||||
}
|
||||
|
||||
func loadSettings(files ...string) *template.Template {
|
||||
func loadSettings(version string, files ...string) *template.Template {
|
||||
files = append(files, "components/settings.tmpl")
|
||||
return load(files...)
|
||||
return load(version, files...)
|
||||
}
|
||||
|
||||
func NewTemplates(logger *slog.Logger) (*Templates, error) {
|
||||
func NewTemplates(version string, logger *slog.Logger) (*Templates, error) {
|
||||
t := Templates{
|
||||
logger: logger,
|
||||
templates: map[string]*template.Template{},
|
||||
|
@ -69,9 +72,9 @@ func NewTemplates(logger *slog.Logger) (*Templates, error) {
|
|||
pathWithoutPrefix := strings.TrimPrefix(path, "pages/")
|
||||
|
||||
if strings.Contains(path, "settings") {
|
||||
t.templates[pathWithoutPrefix] = loadSettings(path)
|
||||
t.templates[pathWithoutPrefix] = loadSettings(version, path)
|
||||
} else {
|
||||
t.templates[pathWithoutPrefix] = load(path)
|
||||
t.templates[pathWithoutPrefix] = load(version, path)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue