diff --git a/internal/handlers/editor.go b/internal/handlers/editor.go index 2440717..f32001c 100644 --- a/internal/handlers/editor.go +++ b/internal/handlers/editor.go @@ -19,7 +19,7 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -27,7 +27,7 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) { return } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "create", gin.H{ "app_name": h.config.AppName, "folder_path": folderPath, "notes_tree": notesTree, @@ -105,7 +105,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { notePath := strings.TrimPrefix(c.Param("path"), "/") if !strings.HasSuffix(notePath, ".md") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid note path", "app_name": h.config.AppName, "message": "Note path must end with .md", @@ -115,7 +115,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { // Security check if strings.Contains(notePath, "..") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid path", "app_name": h.config.AppName, "message": "Path traversal is not allowed", @@ -125,7 +125,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { // Check if path is in skipped directories if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) { - c.HTML(http.StatusForbidden, "base.html", gin.H{ + c.HTML(http.StatusForbidden, "error", gin.H{ "error": "Access denied", "app_name": h.config.AppName, "message": "This note cannot be edited", @@ -136,7 +136,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { fullPath := filepath.Join(h.config.NotesDir, notePath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { - c.HTML(http.StatusNotFound, "base.html", gin.H{ + c.HTML(http.StatusNotFound, "error", gin.H{ "error": "Note not found", "app_name": h.config.AppName, "message": "The requested note does not exist", @@ -146,7 +146,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to read note", "app_name": h.config.AppName, "message": err.Error(), @@ -156,7 +156,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -170,7 +170,7 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { folderPath = "" } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "edit", gin.H{ "app_name": h.config.AppName, "title": title, "content": string(content), diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index c2b4610..58a0246 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -38,7 +38,7 @@ func (h *Handlers) IndexHandler(c *gin.Context) { folderContents, err := utils.GetFolderContents("", h.config) if err != nil { fmt.Printf("DEBUG: Error getting folder contents: %v\n", err) - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to read directory", "app_name": h.config.AppName, "message": err.Error(), @@ -51,7 +51,7 @@ func (h *Handlers) IndexHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { fmt.Printf("DEBUG: Error building tree structure: %v\n", err) - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -61,7 +61,7 @@ func (h *Handlers) IndexHandler(c *gin.Context) { fmt.Printf("DEBUG: Tree structure built, app_name: %s\n", h.config.AppName) - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "folder", gin.H{ "app_name": h.config.AppName, "folder_path": "", "folder_contents": folderContents, @@ -79,7 +79,7 @@ func (h *Handlers) FolderHandler(c *gin.Context) { // Security check - prevent path traversal if strings.Contains(folderPath, "..") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid path", "app_name": h.config.AppName, "message": "Path traversal is not allowed", @@ -89,7 +89,7 @@ func (h *Handlers) FolderHandler(c *gin.Context) { // Check if path is in skipped directories if utils.IsPathInSkippedDirs(folderPath, h.config.NotesDirSkip) { - c.HTML(http.StatusForbidden, "base.html", gin.H{ + c.HTML(http.StatusForbidden, "error", gin.H{ "error": "Access denied", "app_name": h.config.AppName, "message": "This directory is not accessible", @@ -99,7 +99,7 @@ func (h *Handlers) FolderHandler(c *gin.Context) { folderContents, err := utils.GetFolderContents(folderPath, h.config) if err != nil { - c.HTML(http.StatusNotFound, "base.html", gin.H{ + c.HTML(http.StatusNotFound, "error", gin.H{ "error": "Folder not found", "app_name": h.config.AppName, "message": err.Error(), @@ -109,7 +109,7 @@ func (h *Handlers) FolderHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -117,7 +117,7 @@ func (h *Handlers) FolderHandler(c *gin.Context) { return } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "folder", gin.H{ "app_name": h.config.AppName, "folder_path": folderPath, "folder_contents": folderContents, @@ -134,7 +134,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { notePath := strings.TrimPrefix(c.Param("path"), "/") if !strings.HasSuffix(notePath, ".md") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid note path", "app_name": h.config.AppName, "message": "Note path must end with .md", @@ -144,7 +144,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { // Security check if strings.Contains(notePath, "..") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid path", "app_name": h.config.AppName, "message": "Path traversal is not allowed", @@ -154,7 +154,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { // Check if path is in skipped directories if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) { - c.HTML(http.StatusForbidden, "base.html", gin.H{ + c.HTML(http.StatusForbidden, "error", gin.H{ "error": "Access denied", "app_name": h.config.AppName, "message": "This note is not accessible", @@ -165,7 +165,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { fullPath := filepath.Join(h.config.NotesDir, notePath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { - c.HTML(http.StatusNotFound, "base.html", gin.H{ + c.HTML(http.StatusNotFound, "error", gin.H{ "error": "Note not found", "app_name": h.config.AppName, "message": "The requested note does not exist", @@ -175,7 +175,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to read note", "app_name": h.config.AppName, "message": err.Error(), @@ -185,7 +185,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { htmlContent, err := h.renderer.RenderMarkdown(string(content), notePath) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to render markdown", "app_name": h.config.AppName, "message": err.Error(), @@ -195,7 +195,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -209,7 +209,7 @@ func (h *Handlers) NoteHandler(c *gin.Context) { folderPath = "" } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "note", gin.H{ "app_name": h.config.AppName, "title": title, "content": htmlContent, @@ -314,7 +314,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { // Security check if strings.Contains(filePath, "..") { - c.HTML(http.StatusBadRequest, "base.html", gin.H{ + c.HTML(http.StatusBadRequest, "error", gin.H{ "error": "Invalid path", "app_name": h.config.AppName, "message": "Path traversal is not allowed", @@ -325,7 +325,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { fullPath := filepath.Join(h.config.NotesDir, filePath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { - c.HTML(http.StatusNotFound, "base.html", gin.H{ + c.HTML(http.StatusNotFound, "error", gin.H{ "error": "File not found", "app_name": h.config.AppName, "message": "The requested file does not exist", @@ -335,7 +335,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { // Check if file extension is allowed if !models.IsAllowedFile(filePath, h.config.AllowedFileExtensions) { - c.HTML(http.StatusForbidden, "base.html", gin.H{ + c.HTML(http.StatusForbidden, "error", gin.H{ "error": "File type not allowed", "app_name": h.config.AppName, "message": "This file type cannot be viewed", @@ -345,7 +345,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to read file", "app_name": h.config.AppName, "message": err.Error(), @@ -355,7 +355,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -368,7 +368,7 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { folderPath = "" } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "view_text", gin.H{ "app_name": h.config.AppName, "file_name": filepath.Base(filePath), "file_path": filePath, diff --git a/internal/handlers/settings.go b/internal/handlers/settings.go index 8501dd2..cc6e0d3 100644 --- a/internal/handlers/settings.go +++ b/internal/handlers/settings.go @@ -14,7 +14,7 @@ import ( func (h *Handlers) SettingsPageHandler(c *gin.Context) { notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config) if err != nil { - c.HTML(http.StatusInternalServerError, "base.html", gin.H{ + c.HTML(http.StatusInternalServerError, "error", gin.H{ "error": "Failed to build tree structure", "app_name": h.config.AppName, "message": err.Error(), @@ -22,7 +22,7 @@ func (h *Handlers) SettingsPageHandler(c *gin.Context) { return } - c.HTML(http.StatusOK, "base.html", gin.H{ + c.HTML(http.StatusOK, "settings", gin.H{ "app_name": h.config.AppName, "notes_tree": notesTree, "active_path": []string{}, diff --git a/web/templates/base.html b/web/templates/base.html index adc9115..c49d674 100644 --- a/web/templates/base.html +++ b/web/templates/base.html @@ -1,3 +1,4 @@ +{{ define "base" }}
@@ -373,7 +374,7 @@ {{block "scripts" .}}{{end}} - +{{end}} {{define "tree_node"}}