diff --git a/internal/server/config_handler.go b/internal/server/config_handler.go index 8922d0d..8ee2432 100644 --- a/internal/server/config_handler.go +++ b/internal/server/config_handler.go @@ -20,8 +20,7 @@ func (s *Server) handleConfig( return } - section := - r.FormValue("section") + section := r.FormValue("section") switch section { @@ -29,7 +28,17 @@ func (s *Server) handleConfig( err = s.store.SetConfig( "home_path", - r.FormValue("home_path"), + strings.TrimSpace(r.FormValue("home_path")), + ) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = s.store.SetConfig( + "wiki_name", + strings.TrimSpace(r.FormValue("wiki_name")), ) if err != nil { @@ -39,18 +48,14 @@ func (s *Server) handleConfig( case "nav": - labels := - r.Form["nav_label"] - - hrefs := - r.Form["nav_href"] + labels := r.Form["nav_label"] + hrefs := r.Form["nav_href"] var items []NavItem for i := range labels { - label := - strings.TrimSpace(labels[i]) + label := strings.TrimSpace(labels[i]) if label == "" { continue @@ -60,8 +65,7 @@ func (s *Server) handleConfig( continue } - href := - strings.TrimSpace(hrefs[i]) + href := strings.TrimSpace(hrefs[i]) if href == "" { continue @@ -76,8 +80,7 @@ func (s *Server) handleConfig( ) } - raw, err := - json.Marshal(items) + raw, err := json.Marshal(items) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -115,16 +118,25 @@ func (s *Server) handleConfig( return } - homePath, err := - s.store.GetConfig("home_path") + homePath, err := s.store.GetConfig("home_path") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - recent, err := - s.store.ListRecentObjects(50) + wikiName, err := s.store.GetConfig("wiki_name") + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if wikiName == "" { + wikiName = "Pages Wiki" + } + + recent, err := s.store.ListRecentObjects(50) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -136,6 +148,7 @@ func (s *Server) handleConfig( "config.gohtml", map[string]any{ "HomePath": homePath, + "WikiName": wikiName, "Objects": recent, "NavItemsConfig": s.getNavItems(), }, diff --git a/internal/server/render.go b/internal/server/render.go index 20a4afc..54d58d7 100644 --- a/internal/server/render.go +++ b/internal/server/render.go @@ -7,10 +7,12 @@ import ( func mergeTemplateData( data any, nav []NavItem, + wikiName string, ) map[string]any { out := map[string]any{ "NavItems": nav, + "WikiName": wikiName, } if data == nil { @@ -44,6 +46,7 @@ func (s *Server) render( mergeTemplateData( data, s.getNavItems(), + s.getWikiName(), ), ) diff --git a/internal/server/wiki_name.go b/internal/server/wiki_name.go new file mode 100644 index 0000000..a632e56 --- /dev/null +++ b/internal/server/wiki_name.go @@ -0,0 +1,15 @@ +package server + +func (s *Server) getWikiName() string { + + name, err := + s.store.GetConfig( + "wiki_name", + ) + + if err != nil || name == "" { + return "Pages Wiki" + } + + return name +} diff --git a/templates/pages/config.gohtml b/templates/pages/config.gohtml index 3dae4ed..0cb730f 100644 --- a/templates/pages/config.gohtml +++ b/templates/pages/config.gohtml @@ -12,7 +12,7 @@
-Pages Wiki +{{ .WikiName }}
@@ -79,6 +79,21 @@ Navigation value="home" > + + + + +
+
+ + @@ -352,6 +367,84 @@ document.addEventListener( }, ) +function moveNavRow(button, direction) { + + const row = + button.closest( + "tr" + ) + + const tbody = + row.parentElement + + if (direction < 0) { + + const prev = + row.previousElementSibling + + if (prev) { + + tbody.insertBefore( + row, + prev + ) + } + + return + } + + const next = + row.nextElementSibling + + if (next) { + + tbody.insertBefore( + next, + row + ) + } +} + + +function moveNavRow(button, direction) { + + const row = + button.closest( + "tr" + ) + + const tbody = + row.parentElement + + if (direction < 0) { + + const prev = + row.previousElementSibling + + if (prev) { + + tbody.insertBefore( + row, + prev + ) + } + + return + } + + const next = + row.nextElementSibling + + if (next) { + + tbody.insertBefore( + next, + row + ) + } +} + + function moveNavRow(button, direction) { const row = diff --git a/templates/pages/editor.gohtml b/templates/pages/editor.gohtml index ecaf575..04c5891 100644 --- a/templates/pages/editor.gohtml +++ b/templates/pages/editor.gohtml @@ -25,7 +25,7 @@