Delete pages instead of writing empty files
This commit is contained in:
13
main.go
13
main.go
@@ -162,9 +162,16 @@ 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 err := os.WriteFile(indexPath, []byte(content), 0644); err != nil {
|
if strings.TrimSpace(content) == "" {
|
||||||
http.Error(w, "write failed: "+err.Error(), http.StatusInternalServerError)
|
if err := os.Remove(indexPath); err != nil && !os.IsNotExist(err) {
|
||||||
return
|
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)
|
http.Redirect(w, r, urlPath, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user