From 2a82ec8209efbb8a5b9daa75aa952d64f14ccad5 Mon Sep 17 00:00:00 2001
From: Jason Streifling
Date: Thu, 8 Aug 2024 21:09:38 +0200
Subject: [PATCH] Implemented EasyMDE
---
cmd/frontend/articles.go | 15 ++++--
web/templates/editor.html | 79 +++++++++++--------------------
web/templates/index.html | 4 +-
web/templates/rework-article.html | 55 ++++++++++-----------
4 files changed, 67 insertions(+), 86 deletions(-)
diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go
index 2c0ada6..7f95a04 100644
--- a/cmd/frontend/articles.go
+++ b/cmd/frontend/articles.go
@@ -1,9 +1,11 @@
package frontend
import (
+ "encoding/json"
"fmt"
"html/template"
"io"
+ "io/fs"
"log"
"net/http"
"os"
@@ -462,6 +464,12 @@ func UploadImage(c *b.Config) http.HandlerFunc {
return
}
+ if err = os.MkdirAll(fmt.Sprint(c.PicsDir, "/"), fs.FileMode(0755)); err != nil {
+ log.Println(err)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
img, err := os.Create(absFilepath)
if err != nil {
log.Println(err)
@@ -476,10 +484,9 @@ func UploadImage(c *b.Config) http.HandlerFunc {
return
}
- alt := strings.Join(nameStrings[0:len(nameStrings)-1], " ")
- imgMD := fmt.Sprint("![", alt, "](", c.Domain, "/pics/", filename, ")")
- tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
- template.Must(tmpl, err).ExecuteTemplate(w, "editor-images", imgMD)
+ url := fmt.Sprint(c.Domain, "/pics/", filename)
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(url)
}
}
diff --git a/web/templates/editor.html b/web/templates/editor.html
index 35b095a..2dccc55 100644
--- a/web/templates/editor.html
+++ b/web/templates/editor.html
@@ -2,9 +2,6 @@
Editor
{{end}}
-
-{{define "editor-images"}}
-{{if gt (len .) 0}}
-
-{{end}}
-{{end}}
diff --git a/web/templates/index.html b/web/templates/index.html
index 95b36b0..bce30fe 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -6,6 +6,7 @@
Orient Editor
+
@@ -25,7 +26,8 @@
-
+
+