diff --git a/go.mod b/go.mod index 042465b..9c4e119 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/labstack/gommon v0.4.2 github.com/sirupsen/logrus v1.9.3 github.com/tkuchiki/go-timezone v0.2.3 + golang.org/x/net v0.50.0 golang.org/x/text v0.34.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -31,7 +32,6 @@ require ( github.com/valyala/fasttemplate v1.2.2 // indirect golang.org/x/crypto v0.48.0 // indirect golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect - golang.org/x/net v0.50.0 // indirect golang.org/x/sys v0.41.0 // indirect golang.org/x/time v0.11.0 // indirect ) diff --git a/ui/static.go b/ui/static.go index 699ada5..f64cdcb 100644 --- a/ui/static.go +++ b/ui/static.go @@ -72,7 +72,7 @@ func breakUpHTML(r io.Reader) (string, string, error) { if n.Type == html.ElementNode { switch n.Data { case "title": - body = extractPlainText(n) + title = extractPlainText(n) case "body": body = extractInnerHTML(n) } @@ -95,13 +95,20 @@ func breakUpHTML(r io.Reader) (string, string, error) { */ func AmStaticFramePage(staticFS fs.FS, prefix string) AmPageFunc { return func(ctxt AmContext) (string, any) { + // Cut the prefix off the path. fname := ctxt.URLPath() if strings.HasPrefix(fname, prefix) { fname = fname[len(prefix):] } else { return "error", "invalid path name" } + // Extract the basic MIME type. mtype := mimeTypeFromFilename(fname) + p := strings.Index(mtype, ";") + if p >= 0 { + mtype = mtype[:p] + } + // Decide from there how to render it. ctxt.VarMap().Set("mimeType", mtype) switch mtype { case "text/html":