about summary refs log tree commit diff stats
path: root/internal/builder/template.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-18 20:23:27 +0200
committerAlan Pearce2024-05-18 20:23:27 +0200
commit7dc19d115c5f3b012f96284adc8cadb9b703d6db (patch)
tree663783920a624046fed7618dc1bdf1bbf389aaf3 /internal/builder/template.go
parent9a10bbdb7ab8cb4da1002729b463ed9beca13858 (diff)
downloadwebsite-7dc19d115c5f3b012f96284adc8cadb9b703d6db.tar.lz
website-7dc19d115c5f3b012f96284adc8cadb9b703d6db.tar.zst
website-7dc19d115c5f3b012f96284adc8cadb9b703d6db.zip
remove lint errors
Diffstat (limited to 'internal/builder/template.go')
-rw-r--r--internal/builder/template.go55
1 files changed, 45 insertions, 10 deletions
diff --git a/internal/builder/template.go b/internal/builder/template.go
index 74d0418..5bd990e 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -93,7 +93,12 @@ func (root QuerySelection) setImgURL(pageURL string, pageTitle string) QuerySele
 	return root
 }
 
-func layout(filename string, config config.Config, pageTitle string, pageURL string) (*goquery.Document, error) {
+func layout(
+	filename string,
+	config config.Config,
+	pageTitle string,
+	pageURL string,
+) (*goquery.Document, error) {
 	html, err := loadTemplate(filename)
 	if err != nil {
 		return nil, err
@@ -112,6 +117,9 @@ func layout(filename string, config config.Config, pageTitle string, pageURL str
 		}
 		defer countFile.Close()
 		countHTML, err = NewDocumentNoScript(countFile)
+		if err != nil {
+			return
+		}
 		if config.InjectLiveReload {
 			liveReloadFile, err := os.OpenFile("templates/dev.html", os.O_RDONLY, 0)
 			if err != nil {
@@ -119,6 +127,9 @@ func layout(filename string, config config.Config, pageTitle string, pageURL str
 			}
 			defer liveReloadFile.Close()
 			liveReloadHTML, err = goquery.NewDocumentFromReader(liveReloadFile)
+			if err != nil {
+				return
+			}
 		}
 	})
 	if err != nil {
@@ -235,6 +246,9 @@ func renderHomepage(config config.Config, posts []Post, url string) (io.Reader,
 	doc.Find(".title").AddClass("p-name u-url")
 
 	html, err := renderMarkdown(index)
+	if err != nil {
+		return nil, err
+	}
 	doc.Find("#content").SetHtml(html)
 
 	feed := doc.Find(".h-feed")
@@ -277,18 +291,29 @@ func render404(config config.Config, url string) (io.Reader, error) {
 	return renderHTML(doc), nil
 }
 
-func renderFeed(title string, config config.Config, posts []Post, specific string) (io.Reader, error) {
+func renderFeed(
+	title string,
+	config config.Config,
+	posts []Post,
+	specific string,
+) (io.Reader, error) {
 	reader, err := loadTemplate("templates/feed.xml")
 	if err != nil {
 		return nil, err
 	}
 	defer reader.Seek(0, io.SeekStart)
 	doc, err := xmlquery.Parse(reader)
+	if err != nil {
+		return nil, err
+	}
 	feed := doc.SelectElement("feed")
 	feed.SelectElement("title").FirstChild.Data = title
 	feed.SelectElement("link").SetAttr("href", config.BaseURL.String())
 	feed.SelectElement("id").FirstChild.Data = atom.MakeTagURI(config, specific)
 	datetime, err := posts[0].Date.UTC().MarshalText()
+	if err != nil {
+		return nil, err
+	}
 	feed.SelectElement("updated").FirstChild.Data = string(datetime)
 	tpl := feed.SelectElement("entry")
 	xmlquery.RemoveFromTree(tpl)
@@ -313,13 +338,16 @@ func renderFeed(title string, config config.Config, posts []Post, specific strin
 		if err != nil {
 			return nil, err
 		}
-		entry, err := xmlquery.ParseWithOptions(strings.NewReader(string(text)), xmlquery.ParserOptions{
-			Decoder: &xmlquery.DecoderOptions{
-				Strict:    false,
-				AutoClose: xml.HTMLAutoClose,
-				Entity:    xml.HTMLEntity,
+		entry, err := xmlquery.ParseWithOptions(
+			strings.NewReader(string(text)),
+			xmlquery.ParserOptions{
+				Decoder: &xmlquery.DecoderOptions{
+					Strict:    false,
+					AutoClose: xml.HTMLAutoClose,
+					Entity:    xml.HTMLEntity,
+				},
 			},
-		})
+		)
 		if err != nil {
 			return nil, err
 		}
@@ -341,6 +369,9 @@ func renderFeedStyles() (io.Reader, error) {
 		"xhtml": "http://www.w3.org/1999/xhtml",
 	}
 	doc, err := xmlquery.Parse(reader)
+	if err != nil {
+		return nil, err
+	}
 	expr, err := xpath.CompileWithNS("//xhtml:style", nsMap)
 	if err != nil {
 		return nil, err
@@ -358,8 +389,12 @@ func renderHTML(doc *goquery.Document) io.Reader {
 
 	// TODO: return errors to main thread
 	go func() {
-		w.Write([]byte("<!doctype html>\n"))
-		err := htmlformat.Nodes(w, []*html.Node{doc.Children().Get(0)})
+		_, err := w.Write([]byte("<!doctype html>\n"))
+		if err != nil {
+			slog.Error("error writing doctype")
+			w.CloseWithError(err)
+		}
+		err = htmlformat.Nodes(w, []*html.Node{doc.Children().Get(0)})
 		if err != nil {
 			slog.Error("error rendering html", "error", err)
 			w.CloseWithError(err)