fix templating
This commit is contained in:
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user