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
}
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(),
},
+3
View File
@@ -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(),
),
)
+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">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
@@ -79,6 +79,21 @@ Navigation
value="home"
>
<label>
Wiki name
</label>
<input
name="wiki_name"
type="text"
value="{{ .WikiName }}"
placeholder="Pages Wiki"
>
<br>
<br>
<label>
Home semantic path
</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) {
const row =
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
<nav>
+2 -2
View File
@@ -3,7 +3,7 @@
<html lang="en">
<head>
<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/modes.css">
</head>
@@ -12,7 +12,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
<nav>
+1 -1
View File
@@ -12,7 +12,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
+1 -1
View File
@@ -12,7 +12,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
<nav>
+1 -1
View File
@@ -25,7 +25,7 @@
<header class="topbar">
<div class="brand">
<a href="/">Pages Wiki</a>
<a href="/">{{ .WikiName }}</a>
</div>
<nav>