diff --git a/pkg/server/config/config.go b/pkg/server/config/config.go index 33f1c59c..a5d2cc3b 100644 --- a/pkg/server/config/config.go +++ b/pkg/server/config/config.go @@ -105,6 +105,7 @@ type Config struct { DB PostgresConfig PageTemplateDir string StaticDir string + AssetBaseURL string } func getAppEnv() string { @@ -131,6 +132,7 @@ func Load() Config { OnPremise: readBoolEnv("OnPremise"), DisableRegistration: readBoolEnv("DisableRegistration"), DB: loadDBConfig(), + AssetBaseURL: "", } if err := validate(c); err != nil { @@ -155,6 +157,11 @@ func (c *Config) SetStaticDir(d string) { c.StaticDir = d } +// SetAssetBaseURL sets static dir for the confi +func (c *Config) SetAssetBaseURL(d string) { + c.AssetBaseURL = d +} + // IsProd checks if the app environment is configured to be production. func (c Config) IsProd() bool { return c.AppEnv == AppEnvProduction diff --git a/pkg/server/views/helpers.go b/pkg/server/views/helpers.go index ffc6caf0..ee82eb4f 100644 --- a/pkg/server/views/helpers.go +++ b/pkg/server/views/helpers.go @@ -6,12 +6,13 @@ import ( "strings" "time" + "github.com/dnote/dnote/pkg/server/app" "github.com/dnote/dnote/pkg/server/buildinfo" "github.com/pkg/errors" "html/template" ) -func initHelpers(c Config) template.FuncMap { +func initHelpers(c Config, a *app.App) template.FuncMap { ctx := newViewCtx(c) ret := template.FuncMap{ @@ -30,6 +31,9 @@ func initHelpers(c Config) template.FuncMap { "dict": ctx.dict, "defaultValue": ctx.defaultValue, "add": ctx.add, + "assetBaseURL": func() string { + return a.Config.AssetBaseURL + }, } // extend with helpers that are defined specific to a view diff --git a/pkg/server/views/layouts/base.gohtml b/pkg/server/views/layouts/base.gohtml index b94284c4..a79b526c 100644 --- a/pkg/server/views/layouts/base.gohtml +++ b/pkg/server/views/layouts/base.gohtml @@ -6,20 +6,20 @@ {{ title }} - - - - - - - - - - - - + + + + + + + + + + + + - + {{template "css" .}} diff --git a/pkg/server/views/layouts/css.gohtml b/pkg/server/views/layouts/css.gohtml index 86415b9f..90b7bf71 100644 --- a/pkg/server/views/layouts/css.gohtml +++ b/pkg/server/views/layouts/css.gohtml @@ -1,5 +1,5 @@ {{define "css"}} {{range css}} - + {{end}} {{end}} diff --git a/pkg/server/views/layouts/js.gohtml b/pkg/server/views/layouts/js.gohtml index 31db59e4..9267912c 100644 --- a/pkg/server/views/layouts/js.gohtml +++ b/pkg/server/views/layouts/js.gohtml @@ -1,5 +1,5 @@ {{define "js"}} {{range js}} - + {{end}} {{end}} diff --git a/pkg/server/views/view.go b/pkg/server/views/view.go index 5ab67e9c..6d1334b3 100644 --- a/pkg/server/views/view.go +++ b/pkg/server/views/view.go @@ -77,7 +77,7 @@ func NewView(baseDir string, app *app.App, viewConfig Config, files ...string) * files = append(files, layoutFiles(baseDir)...) files = append(files, partialFiles(baseDir)...) - viewHelpers := initHelpers(viewConfig) + viewHelpers := initHelpers(viewConfig, app) t := template.New(viewConfig.Title).Funcs(viewHelpers) t, err := t.ParseFiles(files...)