{{.Content}}+ {{else if eq .Type "image"}} {{else if eq .Type "pdf"}} @@ -94,8 +99,6 @@ Your browser does not support the video tag. - {{else if eq .Type "text"}} -
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 @@
-{{.Content}}+ {{else if eq .Type "image"}} {{else if eq .Type "pdf"}} @@ -94,8 +99,6 @@ Your browser does not support the video tag. - {{else if eq .Type "text"}} -