From 4384cfaa35f7f0a06ef135bd329a6371bcd422ff Mon Sep 17 00:00:00 2001 From: jabuxas Date: Wed, 16 Oct 2024 22:02:08 -0300 Subject: [PATCH] feat: add text support for custom page --- file_display.go | 10 +++++--- templates/files.html | 55 +++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/file_display.go b/file_display.go index 39fe6ad..7cb9a0a 100644 --- a/file_display.go +++ b/file_display.go @@ -4,6 +4,7 @@ import ( "html/template" "log/slog" "net/http" + "os" "path/filepath" "strings" ) @@ -34,10 +35,13 @@ var extensions = map[string]string{ func DisplayFile(app *Application, file string, w http.ResponseWriter) { tmpl := template.Must(template.ParseFiles("templates/files.html")) + fileContent, _ := os.ReadFile("." + file) + fileInfo := FileInfo{ - Name: file, - Path: filepath.Join(app.url, file), - Type: getType(file), + Name: file, + Path: filepath.Join(app.url, file), + Type: getType(file), + Content: string(fileContent), } if err := tmpl.Execute(w, fileInfo); err != nil { diff --git a/templates/files.html b/templates/files.html index 8a408b1..7d1f5ef 100644 --- a/templates/files.html +++ b/templates/files.html @@ -4,13 +4,13 @@ - {{.Name}} + abyss paste @@ -85,7 +88,9 @@
{{.Path}}
- {{if eq .Type "image"}} + {{if eq .Type "text"}} +
{{.Content}}
+ {{else if eq .Type "image"}} Image {{else if eq .Type "pdf"}} @@ -94,8 +99,6 @@ Your browser does not support the video tag. - {{else if eq .Type "text"}} -
{{.Content}}
{{end}}