turos.robert 6 дней назад
Родитель
Сommit
f1095d9b49

+ 1 - 1
cmds/webservice/bin/mynotes_cfg.json

@@ -1,6 +1,6 @@
 {
   "srvhost": "0.0.0.0",
-  "srvport": "3005",
+  "srvport": "3000",
   "notes_directory": "notes_folder",
   "routes": {
     "/list_notes/": "LIST_NOTES",

+ 3 - 3
cmds/webservice/bin/notes_folder/Crima-Si-Pedeapsa/notita-2026-03-24-210114.717444.json

@@ -1,6 +1,6 @@
 {
-  "titlu": "Untitled",
-  "continut": "",
-  "director": "Crima-Si-Pedeapsa",
+  "titlu": "",
+  "continut": "#### Adwasdwasd ",
+  "director": "",
   "Path": "notes_folder/Crima-Si-Pedeapsa/notita-2026-03-24-210114.717444.json"
 }

+ 0 - 6
cmds/webservice/bin/notes_folder/Scoala/notita-2026-03-24-203703.707033.json

@@ -1,6 +0,0 @@
-{
-  "titlu": "wdad",
-  "continut": "dwzda",
-  "director": "Scoala",
-  "Path": "notes_folder/Scoala/notita-2026-03-24-203703.707033.json"
-}

+ 0 - 6
cmds/webservice/bin/notes_folder/Scoala/notita-2026-03-24-204538.379749.json

@@ -1,6 +0,0 @@
-{
-  "titlu": "Untitled",
-  "continut": "",
-  "director": "Scoala",
-  "Path": "notes_folder/Scoala/notita-2026-03-24-204538.379749.json"
-}

+ 6 - 0
cmds/webservice/bin/notes_folder/notes_folder/notita-2026-03-27-210748.187372.json

@@ -0,0 +1,6 @@
+{
+  "titlu": "Untitled",
+  "continut": "",
+  "director": "notes_folder",
+  "Path": "notes_folder/notes_folder/notita-2026-03-27-210748.187372.json"
+}

+ 0 - 6
cmds/webservice/bin/notes_folder/test/test2/notita-2026-03-24-233724.186124.json

@@ -1,6 +0,0 @@
-{
-  "titlu": "Untitled",
-  "continut": "",
-  "director": "test/test2",
-  "Path": "notes_folder/test/test2/notita-2026-03-24-233724.186124.json"
-}

+ 0 - 6
cmds/webservice/bin/notes_folder/test2/notita-2026-03-24-234717.490576.json

@@ -1,6 +0,0 @@
-{
-  "titlu": "Untitled",
-  "continut": "",
-  "director": "test2",
-  "Path": "notes_folder/test2/notita-2026-03-24-234717.490576.json"
-}

+ 12 - 0
cmds/webservice/bin/templates/design/sections/head.tmpl

@@ -33,5 +33,17 @@
     .custom-scrollbar::-webkit-scrollbar-thumb:hover {
         background: #71717a; 
     }
+    .tag {
+    color: #818cf8;
+    text-decoration: none;
+    background: rgba(129, 140, 248, 0.1);
+    padding: 1px 6px;
+    border-radius: 4px;
+    border: 1px solid rgba(129, 140, 248, 0.3);
+    font-size: 0.85em;
+}
+.tag:hover {
+    background: rgba(129, 140, 248, 0.2);
+}
 </style>
 </head>

+ 55 - 3
lib/server/endpoint_funcs.go

@@ -8,6 +8,7 @@ import (
 	"net/http"
 	"os"
 	"path/filepath"
+	"regexp"
 	"strings"
 	"text/template"
 	"time"
@@ -16,6 +17,7 @@ import (
 	"git.linuxit.ro/turos.robert/mynotes/lib/inout"
 	"github.com/yuin/goldmark"
 	"github.com/yuin/goldmark/extension"
+	"github.com/yuin/goldmark/renderer/html"
 )
 
 /*func Notes(w http.ResponseWriter, r *http.Request, fisier string) {
@@ -73,10 +75,12 @@ import (
 }*/
 
 func MDToHTML(w http.ResponseWriter, r *http.Request) {
+
 	body, err := io.ReadAll(r.Body)
 	if err != nil {
 		fmt.Fprintf(w, "%+v", err)
 	}
+
 	mp := make(map[string]any)
 	err = json.Unmarshal(body, &mp)
 	if err != nil {
@@ -84,11 +88,19 @@ func MDToHTML(w http.ResponseWriter, r *http.Request) {
 	}
 	var buff bytes.Buffer
 	md := goldmark.New(
-		goldmark.WithExtensions(extension.Table,
+		goldmark.WithExtensions(
+			extension.Table,
 			extension.DefinitionList,
 			extension.Footnote,
-			extension.Typographer))
-	err = md.Convert([]byte(mp["markdown"].(string)), &buff)
+			extension.Typographer,
+		),
+		goldmark.WithRendererOptions(
+			html.WithUnsafe(),
+		),
+	)
+	tagRegex := regexp.MustCompile(`\[\[([^\[]+)\]\]`)
+	markdown := tagRegex.ReplaceAllString(mp["markdown"].(string), `<a href="/tags/?tag=$1" class="tag">${1}</a>`)
+	err = md.Convert([]byte(markdown), &buff)
 	if err != nil {
 		fmt.Fprintf(w, "%+v", err)
 	}
@@ -175,7 +187,47 @@ func API(w http.ResponseWriter, r *http.Request, s *Server) {
 			} else {
 				http.Redirect(w, r, "/index.html", http.StatusSeeOther)
 			}
+		case "delete_dir":
+			r.ParseForm()
+			path := filepath.Join("./notes_folder", r.Form.Get("path"))
+			fmt.Println(path)
+			err := inout.SafeDir(path)
+			if err != nil {
+				WriteError(w, err)
+				return
+			}
+			err = os.RemoveAll(path)
+			if err != nil {
+				WriteError(w, err)
+				return
+			}
+			referinta := r.Referer()
+			if referinta != "" {
+				http.Redirect(w, r, referinta, http.StatusSeeOther)
+			} else {
+				http.Redirect(w, r, "/index.html", http.StatusSeeOther)
+			}
+		case "delete_file":
+			r.ParseForm()
+			path := filepath.Join("./", r.Form.Get("path"))
+			err := inout.SafeDir(path)
+			if err != nil {
+				WriteError(w, err)
+				return
+			}
+			err = os.Remove(path)
+			if err != nil {
+				WriteError(w, err)
+				return
+			}
+			referinta := r.Referer()
+			if referinta != "" {
+				http.Redirect(w, r, referinta, http.StatusSeeOther)
+			} else {
+				http.Redirect(w, r, "/index.html", http.StatusSeeOther)
+			}
 		}
+
 	}
 	resp, code := inout.ParseTemplate("templates/error.tmpl", fmt.Errorf("method %s not allowed", r.Method))
 	w.Header().Set("Content-Type", "text/html")