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
+27
View File
@@ -23,6 +23,9 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) {
"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",
}) })
} }
@@ -109,6 +115,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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
} }
@@ -119,6 +128,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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
} }
@@ -129,6 +141,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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
} }
@@ -140,6 +155,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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
} }
@@ -150,6 +168,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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
} }
@@ -160,6 +181,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
"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",
}) })
} }
+66
View File
@@ -42,6 +42,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
"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
} }
@@ -55,6 +58,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
"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",
}) })
} }
@@ -83,6 +92,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
"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
} }
@@ -93,6 +105,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
"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
} }
@@ -103,6 +118,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
"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
} }
@@ -113,6 +131,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
"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",
}) })
} }
@@ -138,6 +162,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -148,6 +175,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -158,6 +188,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -169,6 +202,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -179,6 +215,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -189,6 +228,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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
} }
@@ -199,6 +241,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
"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",
}) })
} }
@@ -318,6 +366,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
"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
} }
@@ -329,6 +380,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
"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
} }
@@ -339,6 +393,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
"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
} }
@@ -349,6 +406,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
"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
} }
@@ -359,6 +419,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
"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",
}) })
} }
+6
View File
@@ -18,6 +18,9 @@ func (h *Handlers) SettingsPageHandler(c *gin.Context) {
"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
} }
@@ -31,6 +34,9 @@ func (h *Handlers) SettingsPageHandler(c *gin.Context) {
{"name": "/", "url": "/"}, {"name": "/", "url": "/"},
{"name": "Settings", "url": ""}, {"name": "Settings", "url": ""},
}, },
"ContentTemplate": "settings_content",
"ScriptsTemplate": "settings_scripts",
"Page": "settings",
}) })
} }
+2 -1
View File
@@ -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),
), ),
), ),
+31 -3
View File
@@ -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 -2
View File
@@ -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 -2
View File
@@ -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');
+1 -1
View File
@@ -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 -2
View File
@@ -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');
+3 -3
View File
@@ -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 -2
View File
@@ -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 -2
View File
@@ -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;