From abf3fc3ae356a96dd4ad22f585c9dafa7c4e3931 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 5 Dec 2024 14:54:26 -0500 Subject: [PATCH] Documents can now specify a content-type --- cmd/stepd/handler.go | 4 ++++ document.go | 15 +++++++++------ environment.go | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/stepd/handler.go b/cmd/stepd/handler.go index 12c891d..3641c86 100644 --- a/cmd/stepd/handler.go +++ b/cmd/stepd/handler.go @@ -81,6 +81,10 @@ func (this *handler) serveFile (res http.ResponseWriter, req *http.Request, file this.serveError(res, req, http.StatusInternalServerError, err) return } + if document.ContentType != "" { + log.Println(document.ContentType) + res.Header().Set("Content-Type", document.ContentType) + } err = document.Execute(res, step.ExecutionData { Data: req, }) diff --git a/document.go b/document.go index 5f7e458..6da461c 100644 --- a/document.go +++ b/document.go @@ -7,9 +7,10 @@ import "html/template" // Document represents a STEP file. type Document struct { - Author string - Title string - Extends string + Author string + Title string + Extends string + ContentType string // WORM: environment *Environment @@ -41,6 +42,7 @@ func (this *Document) Execute (output io.Writer, data ExecutionData) error { Author: this.Author, Title: this.Title, Extends: this.Extends, + ContentType: this.ContentType, FrontMatter: this.frontMatter, Body: template.HTML(outputBuilder.String()), }, @@ -55,9 +57,10 @@ type ExecutionData struct { // ExecutionResult is the result of executing a document. type ExecutionResult struct { - Author string - Title string - Extends string + Author string + Title string + Extends string + ContentType string FrontMatter FrontMatter Body template.HTML diff --git a/environment.go b/environment.go index 720be7f..8eeaf6b 100644 --- a/environment.go +++ b/environment.go @@ -106,6 +106,9 @@ func (this *Environment) parse (name string, modTime time.Time, input io.Reader) if extends, ok := frontMatter["extends"]; ok { document.Extends = extends } + if contentType, ok := frontMatter["content-type"]; ok { + document.ContentType = contentType + } // parse template from the body document.template.Funcs(this.funcMap)