about summary refs log tree commit diff stats
path: root/internal/builder
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
parent9a10bbdb7ab8cb4da1002729b463ed9beca13858 (diff)
downloadwebsite-7dc19d115c5f3b012f96284adc8cadb9b703d6db.tar.lz
website-7dc19d115c5f3b012f96284adc8cadb9b703d6db.tar.zst
website-7dc19d115c5f3b012f96284adc8cadb9b703d6db.zip
remove lint errors
Diffstat (limited to 'internal/builder')
-rw-r--r--internal/builder/builder.go7
-rw-r--r--internal/builder/posts.go8
-rw-r--r--internal/builder/template.go55
3 files changed, 57 insertions, 13 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index 90e957c..cb3b670 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -114,7 +114,12 @@ func build(outDir string, config config.Config) error {
 		}
 
 		slog.Debug("rendering tags feed", "tag", tag)
-		output, err = renderFeed(fmt.Sprintf("%s - %s", config.Title, tag), config, matchingPosts, tag)
+		output, err = renderFeed(
+			fmt.Sprintf("%s - %s", config.Title, tag),
+			config,
+			matchingPosts,
+			tag,
+		)
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag feed page")
 		}
diff --git a/internal/builder/posts.go b/internal/builder/posts.go
index 223531b..a4526e4 100644
--- a/internal/builder/posts.go
+++ b/internal/builder/posts.go
@@ -52,13 +52,17 @@ var markdown = goldmark.New(
 func getPost(filename string) (*PostMatter, []byte, error) {
 	matter := PostMatter{}
 	content, err := os.Open(filename)
-	defer content.Close()
 	if err != nil {
 		return nil, nil, errors.WithMessagef(err, "could not open post %s", filename)
 	}
+	defer content.Close()
 	rest, err := frontmatter.MustParse(content, &matter)
 	if err != nil {
-		return nil, nil, errors.WithMessagef(err, "could not parse front matter of post %s", filename)
+		return nil, nil, errors.WithMessagef(
+			err,
+			"could not parse front matter of post %s",
+			filename,
+		)
 	}
 
 	return &matter, rest, nil
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)