fix templating

This commit is contained in:
nahakubuilde
2025-08-25 17:26:27 +01:00
parent 3e47f77ae9
commit 9583224c65
12 changed files with 228 additions and 100 deletions

View File

@@ -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",
})
}