feat: add text support for custom page

This commit is contained in:
jabuxas 2024-10-16 22:02:08 -03:00
parent 6d9dd1aa65
commit 4384cfaa35
2 changed files with 36 additions and 29 deletions

View File

@ -4,6 +4,7 @@ import (
"html/template" "html/template"
"log/slog" "log/slog"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
) )
@ -34,10 +35,13 @@ var extensions = map[string]string{
func DisplayFile(app *Application, file string, w http.ResponseWriter) { func DisplayFile(app *Application, file string, w http.ResponseWriter) {
tmpl := template.Must(template.ParseFiles("templates/files.html")) tmpl := template.Must(template.ParseFiles("templates/files.html"))
fileContent, _ := os.ReadFile("." + file)
fileInfo := FileInfo{ fileInfo := FileInfo{
Name: file, Name: file,
Path: filepath.Join(app.url, file), Path: filepath.Join(app.url, file),
Type: getType(file), Type: getType(file),
Content: string(fileContent),
} }
if err := tmpl.Execute(w, fileInfo); err != nil { if err := tmpl.Execute(w, fileInfo); err != nil {

View File

@ -4,13 +4,13 @@
<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>{{.Name}}</title> <title>abyss paste</title>
<style> <style>
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #1e1e1e; background-color: #1d1f21;
color: #fff; color: #c5c6c7;
font-family: "Arial", sans-serif; font-family: "Arial", sans-serif;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -56,28 +56,31 @@
border: none; border: none;
} }
.btn-download { pre {
display: inline-block; white-space: pre;
padding: 10px 20px; font-family: monospace;
background-color: #36f9f6;
color: #000;
border-radius: 5px;
text-decoration: none;
font-size: 1rem; font-size: 1rem;
transition: background-color 0.3s ease;
}
.btn-download:hover {
background-color: #2bd3d0;
}
footer {
text-align: center;
padding: 10px;
background-color: #2e2e2e; background-color: #2e2e2e;
font-size: 0.8rem; padding: 20px;
color: #aaa; border-radius: 8px;
border-top: 1px solid #36f9f6; overflow: auto;
scrollbar-width: thin;
scrollbar-color: #686868 #2e2e2e;
}
pre::-webkit-scrollbar {
width: 12px;
}
pre::-webkit-scrollbar-track {
background: #2e2e2e;
border-radius: 10px;
}
pre::-webkit-scrollbar-thumb {
background-color: #686868;
border-radius: 10px;
border: 3px solid #2e2e2e;
} }
</style> </style>
</head> </head>
@ -85,7 +88,9 @@
<body> <body>
<header>{{.Path}}</header> <header>{{.Path}}</header>
<div class="content"> <div class="content">
{{if eq .Type "image"}} {{if eq .Type "text"}}
<pre>{{.Content}}</pre>
{{else if eq .Type "image"}}
<img src="{{.Name}}" alt="Image" /> <img src="{{.Name}}" alt="Image" />
{{else if eq .Type "pdf"}} {{else if eq .Type "pdf"}}
<embed src="{{.Name}}" type="application/pdf" class="pdf-embed" /> <embed src="{{.Name}}" type="application/pdf" class="pdf-embed" />
@ -94,8 +99,6 @@
<source src="{{.Name}}" type="video/mp4" /> <source src="{{.Name}}" type="video/mp4" />
Your browser does not support the video tag. Your browser does not support the video tag.
</video> </video>
{{else if eq .Type "text"}}
<div class="text-content">{{.Content}}</div>
{{end}} {{end}}
</div> </div>
</body> </body>