diff --git a/pkg/ext/responses.go b/pkg/ext/responses.go
index 73543951024733b067f4349abded14992d618f34..dbad5b20204f2c8f3d665bf9a7cd7094bdddf328 100644
--- a/pkg/ext/responses.go
+++ b/pkg/ext/responses.go
@@ -6,21 +6,16 @@ "fmt"
"github.com/valyala/fasthttp"
- "git.sr.ht/~gabrielgio/img"
+ "git.sr.ht/~gabrielgio/img/templates"
)
var (
- ContentTypeJSON = []byte("application/json")
- ContentTypeHTML = []byte("text/html")
- ContentTypeMARKDOWN = []byte("text/markdown")
- ContentTypeJPEG = []byte("image/jpeg")
+ ContentTypeHTML = []byte("text/html")
)
func NotFoundHTML(ctx *fasthttp.RequestCtx) {
- ctx.Response.Header.SetContentType("text/html")
- //nolint:errcheck
- img.Render(ctx, "error.html", &img.HTMLView[string]{
- Data: "NotFound",
+ templates.WritePageTemplate(ctx, &templates.ErrorPage{
+ Err: "Not Found",
})
}
@@ -33,16 +28,10 @@ }
}
func InternalServerError(ctx *fasthttp.RequestCtx, err error) {
- ctx.Response.Header.SetContentType("text/html")
- message := fmt.Sprintf("Internal Server Error:\n%+v", err)
- //nolint:errcheck
- respErr := img.Render(ctx, "error.html", &img.HTMLView[string]{
- Data: message,
+ ctx.Response.SetStatusCode(500)
+ templates.WritePageTemplate(ctx, &templates.ErrorPage{
+ Err: fmt.Sprintf("Internal Server Error:\n%s", err.Error()),
})
-
- if respErr != nil {
- fmt.Println(respErr.Error())
- }
}
func NoContent(ctx *fasthttp.RequestCtx) {
diff --git a/templates/error.html b/templates/error.html
deleted file mode 100644
index cbde4001e1afa037aa2cd64d268936c882b6c1cc..0000000000000000000000000000000000000000
--- a/templates/error.html
+++ /dev/null
@@ -1,5 +0,0 @@
-{{template "layout.html" .}}
-{{define "title"}} Not Found {{end}}
-{{define "content"}}
-{{.}}
-{{end}}
diff --git a/templates/error.qtpl b/templates/error.qtpl
new file mode 100644
index 0000000000000000000000000000000000000000..b71adc8794e3bfc0f43978ccb594900210cc38af
--- /dev/null
+++ b/templates/error.qtpl
@@ -0,0 +1,16 @@
+{% code
+type ErrorPage struct {
+ Err string
+}
+%}
+
+{% func (p *ErrorPage) Title() %}
+Error
+{% endfunc %}
+
+{% func (p *ErrorPage) Content() %}
+{%s p.Err %}
+{% endfunc %}
+
+{% func (p *ErrorPage) Script() %}
+{% endfunc %}
diff --git a/templates/media.html b/templates/media.html
deleted file mode 100644
index 188d5b4c2be930218a1ad0f7b5527c53052fc3db..0000000000000000000000000000000000000000
--- a/templates/media.html
+++ /dev/null
@@ -1,24 +0,0 @@
-{{template "layout.html" .}}
-{{define "title"}} {{.Title}} {{end}}
-{{define "content"}}
-<div class="columns is-multiline">
-{{range .Data.Medias}}
-<div class="card">
- <div class="card-image">
- {{ if .IsVideo }}
- <video controls muted="true" poster="/media/thumbnail?path_hash={{.PathHash}}" preload="none">
- <source src="/media/image?path_hash={{.PathHash}}" type="{{.MIMEType}}">
- </video>
- {{ else }}
- <figure class="image is-fit">
- <img src="/media/thumbnail?path_hash={{.PathHash}}">
- </figure>
- {{ end }}
- </div>
-</div>
-{{end}}
-</div>
-<div class="row">
- <a href="/media?page={{.Data.Next.Page}}" class="button is-pulled-right">next</a>
-</div>
-{{end}}
diff --git a/templates/media.qtpl b/templates/media.qtpl
index 88ce5820e3813ff1962f1ab3d4d06e311cebd231..b9b3bf55abe33232484b8d4d7f4b200cf75d3699 100644
--- a/templates/media.qtpl
+++ b/templates/media.qtpl
@@ -11,7 +11,6 @@ {% func (p *MediaPage) Title() %}
Media
{% endfunc %}
-
{% func (p *MediaPage) Content() %}
<div class="columns is-multiline">
{% for _, media := range p.Medias %}