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 {{range .Crumbs}}<span class="sep">/</span
><a href="{{.URL}}">{{.Name}}</a>{{end}} ><a href="{{.URL}}">{{.Name}}</a>{{end}}
</nav> </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> </header>
<main> <main>
{{if .EditMode}} {{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"> <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="bold" data-key="B" title="Bold (B)">**</button>
<button type="button" class="btn-tool" data-action="italic" data-key="I" title="Italic (I)">*</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> <button type="button" class="btn-tool" data-action="hr" data-key="R" title="Horizontal rule (R)">---</button>
</div> </div>
<textarea name="content" id="editor" autofocus>{{.RawContent}}</textarea> <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> </form>
<script src="/_/editor.js"></script> <script src="/_/editor.js"></script>
{{else}} {{if .Content}} {{else}} {{if .Content}}

View File

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

View File

@@ -162,10 +162,17 @@ func (h *handler) handlePost(w http.ResponseWriter, r *http.Request, urlPath, fs
} }
content := r.FormValue("content") content := r.FormValue("content")
indexPath := filepath.Join(fsPath, "index.md") indexPath := filepath.Join(fsPath, "index.md")
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 { if err := os.WriteFile(indexPath, []byte(content), 0644); err != nil {
http.Error(w, "write failed: "+err.Error(), http.StatusInternalServerError) http.Error(w, "write failed: "+err.Error(), http.StatusInternalServerError)
return return
} }
}
http.Redirect(w, r, urlPath, http.StatusSeeOther) http.Redirect(w, r, urlPath, http.StatusSeeOther)
} }