From 2635dce918767736d92c0111ad67be291c5eaa7c Mon Sep 17 00:00:00 2001 From: luxick Date: Fri, 10 Apr 2026 11:46:06 +0200 Subject: [PATCH] Delete pages instead of writing empty files --- main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index b5f8abd..3fcd4b7 100644 --- a/main.go +++ b/main.go @@ -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) }