fix templating
This commit is contained in:
@@ -23,6 +23,9 @@ func (h *Handlers) CreateNotePageHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -109,6 +115,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -119,6 +128,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"error": "Invalid path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Path traversal is not allowed",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -129,6 +141,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"error": "Access denied",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "This note cannot be edited",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -140,6 +155,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -150,6 +168,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"error": "Failed to read note",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -160,6 +181,9 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
|
||||
"error": "Failed to read directory",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -55,6 +58,9 @@ func (h *Handlers) IndexHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,6 +92,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
||||
"error": "Invalid path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Path traversal is not allowed",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -93,6 +105,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
||||
"error": "Access denied",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "This directory is not accessible",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -103,6 +118,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
||||
"error": "Folder not found",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -113,6 +131,9 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,6 +162,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -148,6 +175,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"error": "Invalid path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Path traversal is not allowed",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -158,6 +188,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"error": "Access denied",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "This note is not accessible",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -169,6 +202,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -179,6 +215,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"error": "Failed to read note",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -189,6 +228,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"error": "Failed to render markdown",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -199,6 +241,9 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -318,6 +366,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
||||
"error": "Invalid path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Path traversal is not allowed",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -329,6 +380,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -339,6 +393,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
||||
"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
|
||||
}
|
||||
@@ -349,6 +406,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
||||
"error": "Failed to read file",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -359,6 +419,9 @@ func (h *Handlers) ViewTextHandler(c *gin.Context) {
|
||||
"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",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ func (h *Handlers) SettingsPageHandler(c *gin.Context) {
|
||||
"error": "Failed to build tree structure",
|
||||
"app_name": h.config.AppName,
|
||||
"message": err.Error(),
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -31,6 +34,9 @@ func (h *Handlers) SettingsPageHandler(c *gin.Context) {
|
||||
{"name": "/", "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.WithStyle("github-dark"),
|
||||
highlighting.WithFormatOptions(
|
||||
chromahtml.WithLineNumbers(true),
|
||||
// Disable line numbers in code blocks for cleaner display
|
||||
chromahtml.WithLineNumbers(false),
|
||||
chromahtml.WithClasses(true),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
tailwind.config = {
|
||||
@@ -287,7 +287,21 @@
|
||||
|
||||
<!-- Content Area -->
|
||||
<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>
|
||||
@@ -371,7 +385,21 @@
|
||||
});
|
||||
</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>
|
||||
</html>
|
||||
{{end}}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "create_content"}}
|
||||
<div class="max-w-4xl mx-auto p-6">
|
||||
<!-- Header -->
|
||||
<div class="mb-6">
|
||||
@@ -75,7 +75,7 @@ console.log('Hello, World!');
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "create_scripts"}}
|
||||
<script>
|
||||
const createForm = document.getElementById('create-form');
|
||||
const titleInput = document.getElementById('title');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "edit_content"}}
|
||||
<div class="max-w-4xl mx-auto p-6">
|
||||
<!-- Header -->
|
||||
<div class="mb-6">
|
||||
@@ -73,7 +73,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "edit_scripts"}}
|
||||
<script>
|
||||
const editForm = document.getElementById('edit-form');
|
||||
const contentTextarea = document.getElementById('content');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "error_content"}}
|
||||
<div class="flex items-center justify-center min-h-screen">
|
||||
<div class="max-w-md w-full mx-4">
|
||||
<div class="bg-gray-800 rounded-lg p-8 text-center">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "folder_content"}}
|
||||
<div class="p-6">
|
||||
<!-- Header with upload button -->
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
@@ -109,7 +109,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "folder_scripts"}}
|
||||
<script>
|
||||
let uploadArea = document.getElementById('upload-area');
|
||||
let fileInput = document.getElementById('file-input');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "note_content"}}
|
||||
<div class="max-w-4xl mx-auto p-6">
|
||||
<!-- Note Header -->
|
||||
<div class="mb-6">
|
||||
@@ -29,7 +29,7 @@
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<!-- Note Content -->
|
||||
<!-- Note Content | safeHTML -->
|
||||
<div class="bg-gray-800 rounded-lg p-6">
|
||||
<div class="prose prose-dark max-w-none">
|
||||
{{.content | safeHTML}}
|
||||
@@ -50,7 +50,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "note_scripts"}}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const deleteBtn = document.querySelector('.delete-note-btn');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "settings_content"}}
|
||||
<div class="max-w-6xl mx-auto p-6">
|
||||
<!-- Header -->
|
||||
<div class="mb-8">
|
||||
@@ -156,7 +156,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "settings_scripts"}}
|
||||
<script>
|
||||
// Load current settings
|
||||
function loadSettings() {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{template "base" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{define "view_text_content"}}
|
||||
<div class="max-w-4xl mx-auto p-6">
|
||||
<!-- Header -->
|
||||
<div class="mb-6">
|
||||
@@ -45,7 +45,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{define "view_text_scripts"}}
|
||||
<script>
|
||||
let deleteModal = document.getElementById('delete-modal');
|
||||
let deleteTarget = null;
|
||||
|
||||
Reference in New Issue
Block a user