add config: define custom wiki_name

This commit is contained in:
Anya Tokugawa committed 2026-05-31 21:18:13 +09:00
1 parent 12decb7862
commit 49a88460b4
12 files changed
+152 -28

No files matched your search

+31 -18
View File
@@ -20,8 +20,7 @@ func (s *Server) handleConfig(
return return
} }
section := section := r.FormValue("section")
r.FormValue("section")
switch section { switch section {
@@ -29,7 +28,17 @@ func (s *Server) handleConfig(
err = s.store.SetConfig( err = s.store.SetConfig(
"home_path", "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 { if err != nil {
@@ -39,18 +48,14 @@ func (s *Server) handleConfig(
case "nav": case "nav":
labels := labels := r.Form["nav_label"]
r.Form["nav_label"] hrefs := r.Form["nav_href"]
hrefs :=
r.Form["nav_href"]
var items []NavItem var items []NavItem
for i := range labels { for i := range labels {
label := label := strings.TrimSpace(labels[i])
strings.TrimSpace(labels[i])
if label == "" { if label == "" {
continue continue
@@ -60,8 +65,7 @@ func (s *Server) handleConfig(
continue continue
} }
href := href := strings.TrimSpace(hrefs[i])
strings.TrimSpace(hrefs[i])
if href == "" { if href == "" {
continue continue
@@ -76,8 +80,7 @@ func (s *Server) handleConfig(
) )
} }
raw, err := raw, err := json.Marshal(items)
json.Marshal(items)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -115,16 +118,25 @@ func (s *Server) handleConfig(
return return
} }
homePath, err := homePath, err := s.store.GetConfig("home_path")
s.store.GetConfig("home_path")
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
recent, err := wikiName, err := s.store.GetConfig("wiki_name")
s.store.ListRecentObjects(50)
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 { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -136,6 +148,7 @@ func (s *Server) handleConfig(
"config.gohtml", "config.gohtml",
map[string]any{ map[string]any{
"HomePath": homePath, "HomePath": homePath,
"WikiName": wikiName,
"Objects": recent, "Objects": recent,
"NavItemsConfig": s.getNavItems(), "NavItemsConfig": s.getNavItems(),
}, },
+3
View File
@@ -7,10 +7,12 @@ import (
func mergeTemplateData( func mergeTemplateData(
data any, data any,
nav []NavItem, nav []NavItem,
wikiName string,
) map[string]any { ) map[string]any {
out := map[string]any{ out := map[string]any{
"NavItems": nav, "NavItems": nav,
"WikiName": wikiName,
} }
if data == nil { if data == nil {
@@ -44,6 +46,7 @@ func (s *Server) render(
mergeTemplateData( mergeTemplateData(
data, data,
s.getNavItems(), s.getNavItems(),
s.getWikiName(),
), ),
) )
+15
View File
@@ -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
}
+94 -1
View File
@@ -12,7 +12,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
@@ -79,6 +79,21 @@ Navigation
value="home" value="home"
> >
<label>
Wiki name
</label>
<input
name="wiki_name"
type="text"
value="{{ .WikiName }}"
placeholder="Pages Wiki"
>
<br>
<br>
<label> <label>
Home semantic path Home semantic path
</label> </label>
@@ -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) { function moveNavRow(button, direction) {
const row = const row =
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
<nav> <nav>
+2 -2
View File
@@ -3,7 +3,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Pages Wiki</title> <title>{{ .WikiName }}</title>
<link rel="stylesheet" href="/o/path:/system/static/css/main.css"> <link rel="stylesheet" href="/o/path:/system/static/css/main.css">
<link rel="stylesheet" href="/o/path:/system/static/css/modes.css"> <link rel="stylesheet" href="/o/path:/system/static/css/modes.css">
</head> </head>
@@ -12,7 +12,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
<nav> <nav>
+1 -1
View File
@@ -12,7 +12,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
+1 -1
View File
@@ -12,7 +12,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
<nav> <nav>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar"> <header class="topbar">
<div class="brand"> <div class="brand">
<a href="/">Pages Wiki</a> <a href="/">{{ .WikiName }}</a>
</div> </div>
<nav> <nav>