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)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -34,6 +37,9 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) {
|
|||||||
"active_path": utils.GetActivePath(folderPath),
|
"active_path": utils.GetActivePath(folderPath),
|
||||||
"current_note": nil,
|
"current_note": nil,
|
||||||
"breadcrumbs": utils.GenerateBreadcrumbs(folderPath),
|
"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") {
|
if !strings.HasSuffix(notePath, ".md") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid note path",
|
"error": "Invalid note path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Note path must end with .md",
|
"message": "Note path must end with .md",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -116,9 +125,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
// Security check
|
// Security check
|
||||||
if strings.Contains(notePath, "..") {
|
if strings.Contains(notePath, "..") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid path",
|
"error": "Invalid path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Path traversal is not allowed",
|
"message": "Path traversal is not allowed",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -126,9 +138,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
// Check if path is in skipped directories
|
// Check if path is in skipped directories
|
||||||
if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) {
|
if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) {
|
||||||
c.HTML(http.StatusForbidden, "error", gin.H{
|
c.HTML(http.StatusForbidden, "error", gin.H{
|
||||||
"error": "Access denied",
|
"error": "Access denied",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "This note cannot be edited",
|
"message": "This note cannot be edited",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -137,9 +152,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
||||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||||
"error": "Note not found",
|
"error": "Note not found",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "The requested note does not exist",
|
"message": "The requested note does not exist",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -147,9 +165,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
content, err := os.ReadFile(fullPath)
|
content, err := os.ReadFile(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to read note",
|
"error": "Failed to read note",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -157,9 +178,12 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -180,6 +204,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
|||||||
"active_path": utils.GetActivePath(folderPath),
|
"active_path": utils.GetActivePath(folderPath),
|
||||||
"current_note": notePath,
|
"current_note": notePath,
|
||||||
"breadcrumbs": utils.GenerateBreadcrumbs(folderPath),
|
"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 {
|
if err != nil {
|
||||||
fmt.Printf("DEBUG: Error getting folder contents: %v\n", err)
|
fmt.Printf("DEBUG: Error getting folder contents: %v\n", err)
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to read directory",
|
"error": "Failed to read directory",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -52,9 +55,12 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("DEBUG: Error building tree structure: %v\n", err)
|
fmt.Printf("DEBUG: Error building tree structure: %v\n", err)
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -71,6 +77,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
|
|||||||
"breadcrumbs": utils.GenerateBreadcrumbs(""),
|
"breadcrumbs": utils.GenerateBreadcrumbs(""),
|
||||||
"allowed_image_extensions": h.config.AllowedImageExtensions,
|
"allowed_image_extensions": h.config.AllowedImageExtensions,
|
||||||
"allowed_file_extensions": h.config.AllowedFileExtensions,
|
"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
|
// Security check - prevent path traversal
|
||||||
if strings.Contains(folderPath, "..") {
|
if strings.Contains(folderPath, "..") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid path",
|
"error": "Invalid path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Path traversal is not allowed",
|
"message": "Path traversal is not allowed",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -90,9 +102,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
|||||||
// Check if path is in skipped directories
|
// Check if path is in skipped directories
|
||||||
if utils.IsPathInSkippedDirs(folderPath, h.config.NotesDirSkip) {
|
if utils.IsPathInSkippedDirs(folderPath, h.config.NotesDirSkip) {
|
||||||
c.HTML(http.StatusForbidden, "error", gin.H{
|
c.HTML(http.StatusForbidden, "error", gin.H{
|
||||||
"error": "Access denied",
|
"error": "Access denied",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "This directory is not accessible",
|
"message": "This directory is not accessible",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -100,9 +115,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
|||||||
folderContents, err := utils.GetFolderContents(folderPath, h.config)
|
folderContents, err := utils.GetFolderContents(folderPath, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||||
"error": "Folder not found",
|
"error": "Folder not found",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -110,9 +128,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
|||||||
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -127,6 +148,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
|||||||
"breadcrumbs": utils.GenerateBreadcrumbs(folderPath),
|
"breadcrumbs": utils.GenerateBreadcrumbs(folderPath),
|
||||||
"allowed_image_extensions": h.config.AllowedImageExtensions,
|
"allowed_image_extensions": h.config.AllowedImageExtensions,
|
||||||
"allowed_file_extensions": h.config.AllowedFileExtensions,
|
"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") {
|
if !strings.HasSuffix(notePath, ".md") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid note path",
|
"error": "Invalid note path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Note path must end with .md",
|
"message": "Note path must end with .md",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -145,9 +172,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
// Security check
|
// Security check
|
||||||
if strings.Contains(notePath, "..") {
|
if strings.Contains(notePath, "..") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid path",
|
"error": "Invalid path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Path traversal is not allowed",
|
"message": "Path traversal is not allowed",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,9 +185,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
// Check if path is in skipped directories
|
// Check if path is in skipped directories
|
||||||
if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) {
|
if utils.IsPathInSkippedDirs(notePath, h.config.NotesDirSkip) {
|
||||||
c.HTML(http.StatusForbidden, "error", gin.H{
|
c.HTML(http.StatusForbidden, "error", gin.H{
|
||||||
"error": "Access denied",
|
"error": "Access denied",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "This note is not accessible",
|
"message": "This note is not accessible",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -166,9 +199,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
||||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||||
"error": "Note not found",
|
"error": "Note not found",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "The requested note does not exist",
|
"message": "The requested note does not exist",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -176,9 +212,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
content, err := os.ReadFile(fullPath)
|
content, err := os.ReadFile(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to read note",
|
"error": "Failed to read note",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -186,9 +225,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
htmlContent, err := h.renderer.RenderMarkdown(string(content), notePath)
|
htmlContent, err := h.renderer.RenderMarkdown(string(content), notePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to render markdown",
|
"error": "Failed to render markdown",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -196,9 +238,12 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -219,6 +264,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
|||||||
"active_path": utils.GetActivePath(folderPath),
|
"active_path": utils.GetActivePath(folderPath),
|
||||||
"current_note": notePath,
|
"current_note": notePath,
|
||||||
"breadcrumbs": utils.GenerateBreadcrumbs(folderPath),
|
"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
|
// Security check
|
||||||
if strings.Contains(filePath, "..") {
|
if strings.Contains(filePath, "..") {
|
||||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||||
"error": "Invalid path",
|
"error": "Invalid path",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "Path traversal is not allowed",
|
"message": "Path traversal is not allowed",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -326,9 +377,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
||||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||||
"error": "File not found",
|
"error": "File not found",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "The requested file does not exist",
|
"message": "The requested file does not exist",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -336,9 +390,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
|||||||
// Check if file extension is allowed
|
// Check if file extension is allowed
|
||||||
if !models.IsAllowedFile(filePath, h.config.AllowedFileExtensions) {
|
if !models.IsAllowedFile(filePath, h.config.AllowedFileExtensions) {
|
||||||
c.HTML(http.StatusForbidden, "error", gin.H{
|
c.HTML(http.StatusForbidden, "error", gin.H{
|
||||||
"error": "File type not allowed",
|
"error": "File type not allowed",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": "This file type cannot be viewed",
|
"message": "This file type cannot be viewed",
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -346,9 +403,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
|||||||
content, err := os.ReadFile(fullPath)
|
content, err := os.ReadFile(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to read file",
|
"error": "Failed to read file",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -356,9 +416,12 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
|||||||
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -377,6 +440,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
|||||||
"notes_tree": notesTree,
|
"notes_tree": notesTree,
|
||||||
"active_path": utils.GetActivePath(folderPath),
|
"active_path": utils.GetActivePath(folderPath),
|
||||||
"breadcrumbs": utils.GenerateBreadcrumbs(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)
|
notesTree, err := utils.BuildTreeStructure(h.config.NotesDir, h.config.NotesDirHideSidepane, h.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
c.HTML(http.StatusInternalServerError, "error", gin.H{
|
||||||
"error": "Failed to build tree structure",
|
"error": "Failed to build tree structure",
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
"ContentTemplate": "error_content",
|
||||||
|
"ScriptsTemplate": "error_scripts",
|
||||||
|
"Page": "error",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "settings", gin.H{
|
c.HTML(http.StatusOK, "settings", gin.H{
|
||||||
"app_name": h.config.AppName,
|
"app_name": h.config.AppName,
|
||||||
"notes_tree": notesTree,
|
"notes_tree": notesTree,
|
||||||
"active_path": []string{},
|
"active_path": []string{},
|
||||||
"current_note": nil,
|
"current_note": nil,
|
||||||
"breadcrumbs": []gin.H{
|
"breadcrumbs": []gin.H{
|
||||||
{"name": "/", "url": "/"},
|
{"name": "/", "url": "/"},
|
||||||
{"name": "Settings", "url": ""},
|
{"name": "Settings", "url": ""},
|
||||||
},
|
},
|
||||||
|
"ContentTemplate": "settings_content",
|
||||||
|
"ScriptsTemplate": "settings_scripts",
|
||||||
|
"Page": "settings",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ func NewRenderer(cfg *config.Config) *Renderer {
|
|||||||
highlighting.NewHighlighting(
|
highlighting.NewHighlighting(
|
||||||
highlighting.WithStyle("github-dark"),
|
highlighting.WithStyle("github-dark"),
|
||||||
highlighting.WithFormatOptions(
|
highlighting.WithFormatOptions(
|
||||||
chromahtml.WithLineNumbers(true),
|
// Disable line numbers in code blocks for cleaner display
|
||||||
|
chromahtml.WithLineNumbers(false),
|
||||||
chromahtml.WithClasses(true),
|
chromahtml.WithClasses(true),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{{block "title" .}}{{.app_name}}{{end}}</title>
|
<title>{{.app_name}}</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<script>
|
<script>
|
||||||
tailwind.config = {
|
tailwind.config = {
|
||||||
@@ -287,7 +287,21 @@
|
|||||||
|
|
||||||
<!-- Content Area -->
|
<!-- Content Area -->
|
||||||
<div class="flex-1 overflow-y-auto">
|
<div class="flex-1 overflow-y-auto">
|
||||||
{{block "content" .}}{{end}}
|
{{if eq .Page "folder"}}
|
||||||
|
{{template "folder_content" .}}
|
||||||
|
{{else if eq .Page "note"}}
|
||||||
|
{{template "note_content" .}}
|
||||||
|
{{else if eq .Page "view_text"}}
|
||||||
|
{{template "view_text_content" .}}
|
||||||
|
{{else if eq .Page "create"}}
|
||||||
|
{{template "create_content" .}}
|
||||||
|
{{else if eq .Page "edit"}}
|
||||||
|
{{template "edit_content" .}}
|
||||||
|
{{else if eq .Page "settings"}}
|
||||||
|
{{template "settings_content" .}}
|
||||||
|
{{else if eq .Page "error"}}
|
||||||
|
{{template "error_content" .}}
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -371,7 +385,21 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{block "scripts" .}}{{end}}
|
{{if eq .Page "folder"}}
|
||||||
|
{{template "folder_scripts" .}}
|
||||||
|
{{else if eq .Page "note"}}
|
||||||
|
{{template "note_scripts" .}}
|
||||||
|
{{else if eq .Page "view_text"}}
|
||||||
|
{{template "view_text_scripts" .}}
|
||||||
|
{{else if eq .Page "create"}}
|
||||||
|
{{template "create_scripts" .}}
|
||||||
|
{{else if eq .Page "edit"}}
|
||||||
|
{{template "edit_scripts" .}}
|
||||||
|
{{else if eq .Page "settings"}}
|
||||||
|
{{template "settings_scripts" .}}
|
||||||
|
{{else if eq .Page "error"}}
|
||||||
|
{{template "error_scripts" .}}
|
||||||
|
{{end}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "create_content"}}
|
||||||
<div class="max-w-4xl mx-auto p-6">
|
<div class="max-w-4xl mx-auto p-6">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
@@ -75,7 +75,7 @@ console.log('Hello, World!');
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "create_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
const createForm = document.getElementById('create-form');
|
const createForm = document.getElementById('create-form');
|
||||||
const titleInput = document.getElementById('title');
|
const titleInput = document.getElementById('title');
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "edit_content"}}
|
||||||
<div class="max-w-4xl mx-auto p-6">
|
<div class="max-w-4xl mx-auto p-6">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "edit_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
const editForm = document.getElementById('edit-form');
|
const editForm = document.getElementById('edit-form');
|
||||||
const contentTextarea = document.getElementById('content');
|
const contentTextarea = document.getElementById('content');
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "error_content"}}
|
||||||
<div class="flex items-center justify-center min-h-screen">
|
<div class="flex items-center justify-center min-h-screen">
|
||||||
<div class="max-w-md w-full mx-4">
|
<div class="max-w-md w-full mx-4">
|
||||||
<div class="bg-gray-800 rounded-lg p-8 text-center">
|
<div class="bg-gray-800 rounded-lg p-8 text-center">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "folder_content"}}
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<!-- Header with upload button -->
|
<!-- Header with upload button -->
|
||||||
<div class="flex items-center justify-between mb-6">
|
<div class="flex items-center justify-between mb-6">
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "folder_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
let uploadArea = document.getElementById('upload-area');
|
let uploadArea = document.getElementById('upload-area');
|
||||||
let fileInput = document.getElementById('file-input');
|
let fileInput = document.getElementById('file-input');
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "note_content"}}
|
||||||
<div class="max-w-4xl mx-auto p-6">
|
<div class="max-w-4xl mx-auto p-6">
|
||||||
<!-- Note Header -->
|
<!-- Note Header -->
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Note Content -->
|
<!-- Note Content | safeHTML -->
|
||||||
<div class="bg-gray-800 rounded-lg p-6">
|
<div class="bg-gray-800 rounded-lg p-6">
|
||||||
<div class="prose prose-dark max-w-none">
|
<div class="prose prose-dark max-w-none">
|
||||||
{{.content | safeHTML}}
|
{{.content | safeHTML}}
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "note_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const deleteBtn = document.querySelector('.delete-note-btn');
|
const deleteBtn = document.querySelector('.delete-note-btn');
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "settings_content"}}
|
||||||
<div class="max-w-6xl mx-auto p-6">
|
<div class="max-w-6xl mx-auto p-6">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="mb-8">
|
<div class="mb-8">
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "settings_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
// Load current settings
|
// Load current settings
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "view_text_content"}}
|
||||||
<div class="max-w-4xl mx-auto p-6">
|
<div class="max-w-4xl mx-auto p-6">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{define "view_text_scripts"}}
|
||||||
<script>
|
<script>
|
||||||
let deleteModal = document.getElementById('delete-modal');
|
let deleteModal = document.getElementById('delete-modal');
|
||||||
let deleteTarget = null;
|
let deleteTarget = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user