aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/handlers_pages.go
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-12 12:26:17 +0300
committergrm <grm@eyesin.space>2026-09-12 12:26:17 +0300
commit2b450b66fee4906e746f6e04a6d07a72ff2faf64 (patch)
treeba2dbb3d9b3580113510dbf24d4ffe660cf95b26 /internal/web/handlers_pages.go
parent336199c65d910bbd45a9c5dcbc3beae214d75b98 (diff)
downloadblogspace-2b450b66fee4906e746f6e04a6d07a72ff2faf64.tar.gz
blogspace-2b450b66fee4906e746f6e04a6d07a72ff2faf64.tar.bz2
blogspace-2b450b66fee4906e746f6e04a6d07a72ff2faf64.zip
Insert images straight from the Markdown editor
A shared editor partial adds an "Insert image" file picker plus paste and drag-and-drop on the textarea; a few lines of inline JS upload the file to the existing images endpoint (which now answers JSON when asked) and put the Markdown at the caret. Without JS the same file rides along with the form and is appended to the text on save, so nothing depends on scripting. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/handlers_pages.go')
-rw-r--r--internal/web/handlers_pages.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/web/handlers_pages.go b/internal/web/handlers_pages.go
index db46097..f2f82d1 100644
--- a/internal/web/handlers_pages.go
+++ b/internal/web/handlers_pages.go
@@ -59,14 +59,17 @@ func (s *Server) handlePageSave(w http.ResponseWriter, r *http.Request) {
}
p.Title = strings.TrimSpace(r.FormValue("title"))
p.Slug = strings.TrimSpace(r.FormValue("slug"))
- p.IntroMD = r.FormValue("intro")
+ p.IntroMD = strings.ReplaceAll(r.FormValue("intro"), "\r\n", "\n")
p.ShowInNav = r.FormValue("show_in_nav") == "on"
autoSlug := p.Slug == ""
if autoSlug {
p.Slug = slug.Make(p.Title)
}
+ img, err := s.readUpload(r, "inline_image")
var msg string
switch {
+ case err != nil:
+ msg = "Image not added: " + err.Error()
case p.Title == "" || len(p.Title) > 120:
msg = "Title is required (max 120 characters)."
case !slug.Valid(p.Slug) || reservedPageSlugs[p.Slug]:
@@ -76,8 +79,8 @@ func (s *Server) handlePageSave(w http.ResponseWriter, r *http.Request) {
s.renderStatus(w, r, http.StatusBadRequest, "dashboard/page_form.html", map[string]any{"page": p, "error": msg})
return
}
+ p.IntroMD = appendImageMD(p.IntroMD, img)
p.IntroHTML = markdown.Render(p.IntroMD)
- var err error
base := p.Slug
for n := 1; ; n++ { // generated slugs get -2, -3… on collision; typed ones report the conflict
p.Slug = slug.WithSuffix(base, n)