diff --git a/internal/handlers/editor.go b/internal/handlers/editor.go index f32001c..f899227 100644 --- a/internal/handlers/editor.go +++ b/internal/handlers/editor.go @@ -20,9 +20,12 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -34,6 +37,9 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) { "active_path": utils.GetActivePath(folderPath), "current_note": nil, "breadcrumbs": utils.GenerateBreadcrumbs(folderPath), + "ContentTemplate": "create_content", + "ScriptsTemplate": "create_scripts", + "Page": "create", }) } @@ -106,9 +112,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { if !strings.HasSuffix(notePath, ".md") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid note path", - "app_name": h.config.AppName, - "message": "Note path must end with .md", + "error": "Invalid note path", + "app_name": h.config.AppName, + "message": "Note path must end with .md", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -116,9 +125,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { // Security check if strings.Contains(notePath, "..") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid path", - "app_name": h.config.AppName, - "message": "Path traversal is not allowed", + "error": "Invalid path", + "app_name": h.config.AppName, + "message": "Path traversal is not allowed", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -126,9 +138,12 @@ 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, "error", gin.H{ - "error": "Access denied", - "app_name": h.config.AppName, - "message": "This note cannot be edited", + "error": "Access denied", + "app_name": h.config.AppName, + "message": "This note cannot be edited", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -137,9 +152,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { if _, err := os.Stat(fullPath); os.IsNotExist(err) { c.HTML(http.StatusNotFound, "error", gin.H{ - "error": "Note not found", - "app_name": h.config.AppName, - "message": "The requested note does not exist", + "error": "Note not found", + "app_name": h.config.AppName, + "message": "The requested note does not exist", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -147,9 +165,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to read note", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to read note", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -157,9 +178,12 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -180,6 +204,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) { "active_path": utils.GetActivePath(folderPath), "current_note": notePath, "breadcrumbs": utils.GenerateBreadcrumbs(folderPath), + "ContentTemplate": "edit_content", + "ScriptsTemplate": "edit_scripts", + "Page": "edit", }) } diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 58a0246..503799b 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -39,9 +39,12 @@ func (h *Handlers) IndexHandler(c *gin.Context) { if err != nil { fmt.Printf("DEBUG: Error getting folder contents: %v\n", err) c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to read directory", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to read directory", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -52,9 +55,12 @@ func (h *Handlers) IndexHandler(c *gin.Context) { if err != nil { fmt.Printf("DEBUG: Error building tree structure: %v\n", err) c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -71,6 +77,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) { "breadcrumbs": utils.GenerateBreadcrumbs(""), "allowed_image_extensions": h.config.AllowedImageExtensions, "allowed_file_extensions": h.config.AllowedFileExtensions, + "ContentTemplate": "folder_content", + "ScriptsTemplate": "folder_scripts", + "Page": "folder", }) } @@ -80,9 +89,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) { // Security check - prevent path traversal if strings.Contains(folderPath, "..") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid path", - "app_name": h.config.AppName, - "message": "Path traversal is not allowed", + "error": "Invalid path", + "app_name": h.config.AppName, + "message": "Path traversal is not allowed", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -90,9 +102,12 @@ 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, "error", gin.H{ - "error": "Access denied", - "app_name": h.config.AppName, - "message": "This directory is not accessible", + "error": "Access denied", + "app_name": h.config.AppName, + "message": "This directory is not accessible", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -100,9 +115,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) { folderContents, err := utils.GetFolderContents(folderPath, h.config) if err != nil { c.HTML(http.StatusNotFound, "error", gin.H{ - "error": "Folder not found", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Folder not found", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -110,9 +128,12 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -127,6 +148,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) { "breadcrumbs": utils.GenerateBreadcrumbs(folderPath), "allowed_image_extensions": h.config.AllowedImageExtensions, "allowed_file_extensions": h.config.AllowedFileExtensions, + "ContentTemplate": "folder_content", + "ScriptsTemplate": "folder_scripts", + "Page": "folder", }) } @@ -135,9 +159,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) { if !strings.HasSuffix(notePath, ".md") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid note path", - "app_name": h.config.AppName, - "message": "Note path must end with .md", + "error": "Invalid note path", + "app_name": h.config.AppName, + "message": "Note path must end with .md", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -145,9 +172,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) { // Security check if strings.Contains(notePath, "..") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid path", - "app_name": h.config.AppName, - "message": "Path traversal is not allowed", + "error": "Invalid path", + "app_name": h.config.AppName, + "message": "Path traversal is not allowed", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -155,9 +185,12 @@ 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, "error", gin.H{ - "error": "Access denied", - "app_name": h.config.AppName, - "message": "This note is not accessible", + "error": "Access denied", + "app_name": h.config.AppName, + "message": "This note is not accessible", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -166,9 +199,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) { if _, err := os.Stat(fullPath); os.IsNotExist(err) { c.HTML(http.StatusNotFound, "error", gin.H{ - "error": "Note not found", - "app_name": h.config.AppName, - "message": "The requested note does not exist", + "error": "Note not found", + "app_name": h.config.AppName, + "message": "The requested note does not exist", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -176,9 +212,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to read note", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to read note", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -186,9 +225,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) { htmlContent, err := h.renderer.RenderMarkdown(string(content), notePath) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to render markdown", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to render markdown", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -196,9 +238,12 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -219,6 +264,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) { "active_path": utils.GetActivePath(folderPath), "current_note": notePath, "breadcrumbs": utils.GenerateBreadcrumbs(folderPath), + "ContentTemplate": "note_content", + "ScriptsTemplate": "note_scripts", + "Page": "note", }) } @@ -315,9 +363,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { // Security check if strings.Contains(filePath, "..") { c.HTML(http.StatusBadRequest, "error", gin.H{ - "error": "Invalid path", - "app_name": h.config.AppName, - "message": "Path traversal is not allowed", + "error": "Invalid path", + "app_name": h.config.AppName, + "message": "Path traversal is not allowed", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -326,9 +377,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { if _, err := os.Stat(fullPath); os.IsNotExist(err) { c.HTML(http.StatusNotFound, "error", gin.H{ - "error": "File not found", - "app_name": h.config.AppName, - "message": "The requested file does not exist", + "error": "File not found", + "app_name": h.config.AppName, + "message": "The requested file does not exist", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -336,9 +390,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { // Check if file extension is allowed if !models.IsAllowedFile(filePath, h.config.AllowedFileExtensions) { c.HTML(http.StatusForbidden, "error", gin.H{ - "error": "File type not allowed", - "app_name": h.config.AppName, - "message": "This file type cannot be viewed", + "error": "File type not allowed", + "app_name": h.config.AppName, + "message": "This file type cannot be viewed", + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -346,9 +403,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { content, err := os.ReadFile(fullPath) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{ - "error": "Failed to read file", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to read file", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -356,9 +416,12 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } @@ -377,6 +440,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) { "notes_tree": notesTree, "active_path": utils.GetActivePath(folderPath), "breadcrumbs": utils.GenerateBreadcrumbs(folderPath), + "ContentTemplate": "view_text_content", + "ScriptsTemplate": "view_text_scripts", + "Page": "view_text", }) } diff --git a/internal/handlers/settings.go b/internal/handlers/settings.go index cc6e0d3..9fe4dcc 100644 --- a/internal/handlers/settings.go +++ b/internal/handlers/settings.go @@ -15,22 +15,28 @@ 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, "error", gin.H{ - "error": "Failed to build tree structure", - "app_name": h.config.AppName, - "message": err.Error(), + "error": "Failed to build tree structure", + "app_name": h.config.AppName, + "message": err.Error(), + "ContentTemplate": "error_content", + "ScriptsTemplate": "error_scripts", + "Page": "error", }) return } c.HTML(http.StatusOK, "settings", gin.H{ - "app_name": h.config.AppName, - "notes_tree": notesTree, - "active_path": []string{}, - "current_note": nil, + "app_name": h.config.AppName, + "notes_tree": notesTree, + "active_path": []string{}, + "current_note": nil, "breadcrumbs": []gin.H{ {"name": "/", "url": "/"}, {"name": "Settings", "url": ""}, }, + "ContentTemplate": "settings_content", + "ScriptsTemplate": "settings_scripts", + "Page": "settings", }) } diff --git a/internal/markdown/renderer.go b/internal/markdown/renderer.go index bdf92b5..4bf5927 100644 --- a/internal/markdown/renderer.go +++ b/internal/markdown/renderer.go @@ -32,7 +32,8 @@ func NewRenderer(cfg *config.Config) *Renderer { highlighting.NewHighlighting( highlighting.WithStyle("github-dark"), highlighting.WithFormatOptions( - chromahtml.WithLineNumbers(true), + // Disable line numbers in code blocks for cleaner display + chromahtml.WithLineNumbers(false), chromahtml.WithClasses(true), ), ), diff --git a/web/templates/base.html b/web/templates/base.html index c49d674..a81bbea 100644 --- a/web/templates/base.html +++ b/web/templates/base.html @@ -4,7 +4,7 @@
-