Compare commits

..

2 Commits

Author SHA1 Message Date
22a4d2d18b Unify Edit/save/cancel buttons 2026-04-10 11:46:31 +02:00
2635dce918 Delete pages instead of writing empty files 2026-04-10 11:46:06 +02:00
3 changed files with 17 additions and 15 deletions

View File

@@ -15,11 +15,16 @@
{{range .Crumbs}}<span class="sep">/</span
><a href="{{.URL}}">{{.Name}}</a>{{end}}
</nav>
{{if .CanEdit}}<a class="edit-btn" href="?edit" title="Edit (E)">EDIT</a>{{end}}
{{if .EditMode}}
<a class="btn-cancel" href="{{.PostURL}}">CANCEL</a>
<button class="btn-save" type="submit" form="edit-form" data-action="save" data-key="S" title="Save (S)">SAVE</button>
{{else if .CanEdit}}
<a class="edit-btn" href="?edit" title="Edit (Alt+Shift+E)">EDIT</a>
{{end}}
</header>
<main>
{{if .EditMode}}
<form class="edit-form" method="POST" action="{{.PostURL}}">
<form id="edit-form" class="edit-form" method="POST" action="{{.PostURL}}">
<div class="editor-toolbar">
<button type="button" class="btn-tool" data-action="bold" data-key="B" title="Bold (B)">**</button>
<button type="button" class="btn-tool" data-action="italic" data-key="I" title="Italic (I)">*</button>
@@ -38,10 +43,6 @@
<button type="button" class="btn-tool" data-action="hr" data-key="R" title="Horizontal rule (R)">---</button>
</div>
<textarea name="content" id="editor" autofocus>{{.RawContent}}</textarea>
<div class="form-actions">
<a class="btn-cancel" href="{{.PostURL}}">CANCEL</a>
<button class="btn-save" type="submit" data-action="save" data-key="S" title="Save (S)">SAVE</button>
</div>
</form>
<script src="/_/editor.js"></script>
{{else}} {{if .Content}}

View File

@@ -303,12 +303,6 @@ textarea:focus {
box-shadow: 0 0 5px #0a0;
}
.form-actions {
display: flex;
gap: 0.75rem;
justify-content: flex-end;
}
.btn-save {
background: none;
border: none;

13
main.go
View File

@@ -162,9 +162,16 @@ func (h *handler) handlePost(w http.ResponseWriter, r *http.Request, urlPath, fs
}
content := r.FormValue("content")
indexPath := filepath.Join(fsPath, "index.md")
if err := os.WriteFile(indexPath, []byte(content), 0644); err != nil {
http.Error(w, "write failed: "+err.Error(), http.StatusInternalServerError)
return
if strings.TrimSpace(content) == "" {
if err := os.Remove(indexPath); err != nil && !os.IsNotExist(err) {
http.Error(w, "delete failed: "+err.Error(), http.StatusInternalServerError)
return
}
} else {
if err := os.WriteFile(indexPath, []byte(content), 0644); err != nil {
http.Error(w, "write failed: "+err.Error(), http.StatusInternalServerError)
return
}
}
http.Redirect(w, r, urlPath, http.StatusSeeOther)
}