M cmd/gohome/main.go => cmd/gohome/main.go +8 -4
@@ 75,8 75,15 @@ func run() error {
gohome.Middleware(root),
)
+ staticHandler := http.StripPrefix(root, http.FileServer(http.FS(gohome.StaticFS)))
+ e.GET(fmt.Sprintf("%s/static/*", root), echo.WrapHandler(staticHandler))
+
svc := e.Group(root)
gohome.NewService(svc)
+
+ srv.AddStaticFunc(
+ gohome.AddGlobalTmpl,
+ )
srv.AddFuncs(template.FuncMap{
"staticURL": func(path string) string {
url, _ := url.JoinPath(config.StaticURL, path)
@@ 96,20 103,17 @@ func run() error {
if err != nil {
return err
}
- staticHandler := http.FileServer(http.FS(gohome.StaticFS))
- e.GET("/static/*", echo.WrapHandler(staticHandler))
if len(os.Args) > 1 {
switch os.Args[1] {
case "migrate":
migrations := cmd.GetMigrations()
- return migrate.Command(db, migrations, migrate.DOLLAR)
+ return migrate.Command(db, migrations, migrate.QUESTION)
default:
return fmt.Errorf("Unknown command '%s'", os.Args[1])
}
}
srv.Run()
-
return nil
}
M config.example.ini => config.example.ini +5 -13
@@ 17,19 17,11 @@ email-service=console
# Default: fs
storage-service=fs
-# Static URL
-# default: /static
-static-url=/static
-
-# Media URL
-# default: /media
-media-url=/media
-
# Admin email
-admin-email=geeks@netlandish.com
+admin-email=admin@yourdomain.com
# Default email to send from
-default-from-email=peter@netlandish.com
+default-from-email=gohome@yourdomain.com
# Email addmin errors?
# Default: true
@@ 38,12 30,12 @@ email-admin-errors=true
# Language
default-language=en
-scheme=http
-domain=127.0.0.1:8000
+scheme=https
+domain=yourdomain.com
[database]
# Path to sqlite3 db file
-connection-string = gohome.db
+connection-string = /path/to/gohome.db
[storage]
# Section for file storage variables
M embed.go => embed.go +1 -1
@@ 5,7 5,7 @@ import "embed"
var (
//go:embed templates
TemplateFS embed.FS
- //go:embed static/*
+ //go:embed static
StaticFS embed.FS
//go:embed migrations
MigrateFS embed.FS
M middleware.go => middleware.go +1 -0
@@ 46,6 46,7 @@ func RepoMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
if !strings.HasPrefix(path, "/") {
path = fmt.Sprintf("/%s", path)
}
+
adminPath := c.Echo().Reverse("home:admin_home")
if strings.HasPrefix(path, adminPath) {
// Using the --admin-- url routes. Don't bother doing any
M utils.go => utils.go +13 -0
@@ 1,7 1,11 @@
package gohome
import (
+ "strings"
+
"github.com/labstack/echo/v4"
+ "netlandish.com/x/gobwebs"
+ "netlandish.com/x/gobwebs/server"
"netlandish.com/x/gobwebs/sessions"
)
@@ 28,3 32,12 @@ func AuthLogout(c echo.Context) error {
sm.Clear(c.Request().Context())
return nil
}
+
+// AddGlobalTmpl adds global template variables
+func AddGlobalTmpl(c echo.Context) gobwebs.Map {
+ gctx := c.(*server.Context)
+ gmap := gobwebs.Map{}
+ serverVersion := strings.Split(strings.Split(gctx.Server.AppInfo(), " ")[1], "-")
+ gmap["serverVersion"] = serverVersion[len(serverVersion)-1]
+ return gmap
+}