about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cmd/build/main.go332
-rw-r--r--go.mod20
-rw-r--r--go.sum7
-rw-r--r--internal/config/config.go18
4 files changed, 264 insertions, 113 deletions
diff --git a/cmd/build/main.go b/cmd/build/main.go
index 0776951..6519fa8 100644
--- a/cmd/build/main.go
+++ b/cmd/build/main.go
@@ -4,7 +4,9 @@ import (
 	"bytes"
 	"encoding/xml"
 	"fmt"
+	"io/fs"
 	"log"
+	"log/slog"
 	"os"
 	"path"
 	"path/filepath"
@@ -14,11 +16,13 @@ import (
 
 	. "alanpearce.eu/website/internal/config"
 
+	"github.com/BurntSushi/toml"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/adrg/frontmatter"
 	"github.com/antchfx/xmlquery"
 	"github.com/antchfx/xpath"
 	mapset "github.com/deckarep/golang-set/v2"
+	"github.com/pkg/errors"
 	"github.com/yuin/goldmark"
 	"github.com/yuin/goldmark/extension"
 	"github.com/yuin/goldmark/renderer/html"
@@ -44,30 +48,31 @@ type Post struct {
 
 type Tags mapset.Set[string]
 
-func check(err error) {
-	if err != nil {
-		log.Panic(err)
-	}
-}
-
-func getPost(filename string) (PostMatter, []byte) {
+func getPost(filename string) (*PostMatter, *[]byte, error) {
 	matter := PostMatter{}
 	content, err := os.Open(filename)
-	check(err)
-	rest, err := frontmatter.Parse(content, &matter)
-	check(err)
+	defer content.Close()
+	if err != nil {
+		return nil, nil, errors.WithMessagef(err, "could not open post %s", filename)
+	}
+	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 matter, rest
+	return &matter, &rest, nil
 }
 
-func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags) {
+func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, error) {
 	tags := mapset.NewSet[string]()
 	posts := []Post{}
 	subdir := filepath.Join(root, inputDir)
 	files, err := os.ReadDir(subdir)
+	if err != nil {
+		return nil, nil, errors.WithMessagef(err, "could not read post directory %s", subdir)
+	}
 	outputReplacer := strings.NewReplacer(root, outputDir, ".md", "/index.html")
 	urlReplacer := strings.NewReplacer(root, "", ".md", "/")
-	check(err)
 	md := goldmark.New(
 		goldmark.WithRendererOptions(
 			html.WithUnsafe(),
@@ -80,25 +85,28 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags) {
 	)
 	for _, f := range files {
 		pathFromRoot := filepath.Join(subdir, f.Name())
-		check(err)
 		if !f.IsDir() && path.Ext(pathFromRoot) == ".md" {
 			output := outputReplacer.Replace(pathFromRoot)
 			url := urlReplacer.Replace(pathFromRoot)
-			matter, content := getPost(pathFromRoot)
+			matter, content, err := getPost(pathFromRoot)
+			if err != nil {
+				return nil, nil, err
+			}
 
 			for _, tag := range matter.Taxonomies.Tags {
 				tags.Add(strings.ToLower(tag))
 			}
 
 			var buf bytes.Buffer
-			err := md.Convert(content, &buf)
-			check(err)
+			if err := md.Convert(*content, &buf); err != nil {
+				return nil, nil, errors.WithMessage(err, "could not convert markdown content")
+			}
 			post := Post{
 				Input:      pathFromRoot,
 				Output:     output,
 				Basename:   filepath.Base(url),
 				URL:        url,
-				PostMatter: matter,
+				PostMatter: *matter,
 				Content:    buf.String(),
 			}
 
@@ -108,15 +116,23 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags) {
 	slices.SortFunc(posts, func(a, b Post) int {
 		return b.Date.Compare(a.Date)
 	})
-	return posts, tags
+	return posts, tags, nil
 }
 
-func layout(filename string, config Config, pageTitle string) *goquery.Document {
-	css, err := os.ReadFile("templates/style.css")
-	check(err)
+func layout(filename string, config Config, pageTitle string) (*goquery.Document, error) {
 	html, err := os.Open(filename)
+	if err != nil {
+		return nil, err
+	}
+	defer html.Close()
+	css, err := os.ReadFile("templates/style.css")
+	if err != nil {
+		return nil, err
+	}
 	doc, err := goquery.NewDocumentFromReader(html)
-	check(err)
+	if err != nil {
+		return nil, err
+	}
 	doc.Find("html").SetAttr("lang", config.DefaultLanguage)
 	doc.Find("head > link[rel=alternate]").SetAttr("title", config.Title)
 	doc.Find(".title").SetText(config.Title)
@@ -128,14 +144,19 @@ func layout(filename string, config Config, pageTitle string) *goquery.Document
 	for _, link := range config.Menus["main"] {
 		nav.AppendSelection(navLink.Clone().SetAttr("href", link.URL).SetText(link.Name))
 	}
-	return doc
+	return doc, nil
 }
 
-func renderPost(post Post, config Config) string {
-	doc := layout("templates/post.html", config, post.PostMatter.Title)
+func renderPost(post Post, config Config) (string, error) {
+	doc, err := layout("templates/post.html", config, post.PostMatter.Title)
+	if err != nil {
+		return "", err
+	}
 	doc.Find(".title").AddClass("h-card p-author").SetAttr("rel", "author")
 	datetime, err := post.PostMatter.Date.MarshalText()
-	check(err)
+	if err != nil {
+		return "", err
+	}
 	doc.Find(".h-entry .dt-published").SetAttr("datetime", string(datetime)).SetText(
 		post.PostMatter.Date.Format("2006-01-02"),
 	)
@@ -146,13 +167,14 @@ func renderPost(post Post, config Config) string {
 	for _, tag := range post.Taxonomies.Tags {
 		categories.AppendSelection(cat.Clone().Find(".p-category").SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag)).Parent()
 	}
-	html, err := doc.Html()
-	check(err)
-	return html
+	return doc.Html()
 }
 
-func renderTags(tags Tags, config Config) string {
-	doc := layout("templates/tags.html", config, config.Title)
+func renderTags(tags Tags, config Config) (string, error) {
+	doc, err := layout("templates/tags.html", config, config.Title)
+	if err != nil {
+		return "", err
+	}
 	tagList := doc.Find(".tags")
 	tpl := doc.Find(".h-feed")
 	tpl.Remove()
@@ -161,19 +183,20 @@ func renderTags(tags Tags, config Config) string {
 			tpl.Clone().SetAttr("href", fmt.Sprintf("/tags/%s/", tag)).SetText("#" + tag),
 		)
 	}
-	html, err := doc.Html()
-	check(err)
-	return html
+	return doc.Html()
 }
 
-func renderListPage(tag string, config Config, posts []Post) string {
+func renderListPage(tag string, config Config, posts []Post) (string, error) {
 	var title string
 	if len(tag) > 0 {
 		title = tag
 	} else {
 		title = config.Title
 	}
-	doc := layout("templates/list.html", config, title)
+	doc, err := layout("templates/list.html", config, title)
+	if err != nil {
+		return "", err
+	}
 	feed := doc.Find(".h-feed")
 	tpl := feed.Find(".h-entry")
 	tpl.Remove()
@@ -188,28 +211,35 @@ func renderListPage(tag string, config Config, posts []Post) string {
 	for _, post := range posts {
 		entry := tpl.Clone()
 		datetime, err := post.PostMatter.Date.MarshalText()
-		check(err)
+		if err != nil {
+			return "", err
+		}
 
 		entry.Find(".p-name").SetText(post.Title).SetAttr("href", post.URL)
 		entry.Find(".dt-published").SetAttr("datetime", string(datetime)).SetText(post.PostMatter.Date.Format("2006-01-02"))
 		feed.AppendSelection(entry)
 	}
 
-	html, err := doc.Html()
-	check(err)
-	return html
+	return doc.Html()
 }
 
-func renderHomepage(config Config, posts []Post) string {
-	_, index := getPost("content/_index.md")
-	doc := layout("templates/homepage.html", config, config.Title)
+func renderHomepage(config Config, posts []Post) (string, error) {
+	_, index, err := getPost("content/_index.md")
+	if err != nil {
+		return "", err
+	}
+	doc, err := layout("templates/homepage.html", config, config.Title)
+	if err != nil {
+		return "", err
+	}
 	doc.Find("body").AddClass("h-card")
 	doc.Find(".title").AddClass("p-name u-url")
 	var buf bytes.Buffer
 
 	md := goldmark.New(goldmark.WithRendererOptions(html.WithUnsafe()))
-	err := md.Convert(index, &buf)
-	check(err)
+	if err := md.Convert(*index, &buf); err != nil {
+		return "", err
+	}
 	doc.Find("#content").SetHtml(buf.String())
 
 	feed := doc.Find(".h-feed")
@@ -221,7 +251,9 @@ func renderHomepage(config Config, posts []Post) string {
 		entry.Find(".p-name").SetText(post.Title)
 		entry.Find(".u-url").SetAttr("href", post.URL)
 		datetime, err := post.PostMatter.Date.MarshalText()
-		check(err)
+		if err != nil {
+			return "", err
+		}
 		entry.
 			Find(".dt-published").
 			SetAttr("datetime", string(datetime)).
@@ -243,21 +275,23 @@ func renderHomepage(config Config, posts []Post) string {
 		elsewhere.AppendSelection(el)
 	}
 
-	html, err := doc.Html()
-	check(err)
-	return html
+	return doc.Html()
 }
 
-func render404(config Config) string {
-	doc := layout("templates/404.html", config, "404 Not Found")
-	html, err := doc.Html()
-	check(err)
-	return html
+func render404(config Config) (string, error) {
+	doc, err := layout("templates/404.html", config, "404 Not Found")
+	if err != nil {
+		return "", err
+	}
+	return doc.Html()
 }
 
-func renderFeed(title string, config Config, posts []Post, specific string) string {
+func renderFeed(title string, config Config, posts []Post, specific string) (string, error) {
 	reader, err := os.Open("templates/feed.xml")
-	check(err)
+	if err != nil {
+		return "", err
+	}
+	defer reader.Close()
 	doc, err := xmlquery.Parse(reader)
 	feed := doc.SelectElement("feed")
 	feed.SelectElement("title").FirstChild.Data = title
@@ -281,7 +315,9 @@ func renderFeed(title string, config Config, posts []Post, specific string) stri
 				Type:    "html",
 			},
 		}, "  ", "    ")
-		check(err)
+		if err != nil {
+			return "", err
+		}
 		entry, err := xmlquery.ParseWithOptions(strings.NewReader(string(text)), xmlquery.ParserOptions{
 			Decoder: &xmlquery.DecoderOptions{
 				Strict:    false,
@@ -289,54 +325,87 @@ func renderFeed(title string, config Config, posts []Post, specific string) stri
 				Entity:    xml.HTMLEntity,
 			},
 		})
-		check(err)
+		if err != nil {
+			return "", err
+		}
 		xmlquery.AddChild(feed, entry.SelectElement("entry"))
 	}
 
-	return doc.OutputXML(true)
+	return doc.OutputXML(true), nil
 }
 
-func renderFeedStyles() string {
+func renderFeedStyles() (string, error) {
 	reader, err := os.Open("templates/feed-styles.xsl")
+	if err != nil {
+		return "", err
+	}
+	defer reader.Close()
 	nsMap := map[string]string{
 		"xsl":   "http://www.w3.org/1999/XSL/Transform",
 		"atom":  "http://www.w3.org/2005/Atom",
 		"xhtml": "http://www.w3.org/1999/xhtml",
 	}
-	check(err)
 	doc, err := xmlquery.Parse(reader)
 	expr, err := xpath.CompileWithNS("//xhtml:style", nsMap)
-	check(err)
+	if err != nil {
+		return "", err
+	}
 	style := xmlquery.QuerySelector(doc, expr)
 	css, err := os.ReadFile("templates/style.css")
-	check(err)
+	if err != nil {
+		return "", err
+	}
 	xmlquery.AddChild(style, &xmlquery.Node{
 		Type: xmlquery.TextNode,
 		Data: string(css),
 	})
-	return doc.OutputXML(true)
+	return doc.OutputXML(true), nil
 }
 
-func main() {
-	err, config := GetConfig()
+type errFiler struct {
+	err error
+}
+
+func build() error {
+	config, err := GetConfig()
+	if err != nil {
+		return err
+	}
 	outDir := "new"
-	check(err)
-	err = os.MkdirAll(path.Join(outDir, "post"), 0755)
-	check(err)
-	log.Print("Generating site...")
-	posts, tags := readPosts("content", "post", outDir)
+	if err := os.MkdirAll(path.Join(outDir, "post"), 0755); err != nil {
+		return errors.WithMessage(err, "could not create post output directory")
+	}
+	posts, tags, err := readPosts("content", "post", outDir)
+	if err != nil {
+		return err
+	}
+
 	for _, post := range posts {
-		err := os.MkdirAll(path.Join(outDir, "post", post.Basename), 0755)
-		check(err)
-		// output := renderPost(post, config)
-		// err = os.WriteFile(post.Output, []byte(output), 0755)
-		// check(err)
-	}
-	err = os.MkdirAll(path.Join(outDir, "tags"), 0755)
-	check(err)
-	// fmt.Printf("%+v\n", renderTags(tags, config))
-	// err = os.WriteFile(path.Join(outDir, "tags", "index.html"), []byte(renderTags(tags, config)), 0755)
-	// check(err)
+		dst := path.Join(outDir, "post", post.Basename)
+		if err := os.MkdirAll(dst, 0755); err != nil {
+			return errors.WithMessagef(err, "could not create directory for post %s", dst)
+		}
+		output, err := renderPost(post, *config)
+		if err != nil {
+			return errors.WithMessagef(err, "could not render post %s", post.Input)
+		}
+		if err := os.WriteFile(post.Output, []byte(output), 0755); err != nil {
+			return errors.WithMessage(err, "could not write output file")
+		}
+	}
+
+	if err := os.MkdirAll(path.Join(outDir, "tags"), 0755); err != nil {
+		return errors.WithMessage(err, "could not create directory for tags")
+	}
+	tagsHtml, err := renderTags(tags, *config)
+	if err != nil {
+		return errors.WithMessage(err, "could not render tags")
+	}
+	err = os.WriteFile(path.Join(outDir, "tags", "index.html"), []byte(tagsHtml), 0644)
+	if err != nil {
+		return errors.WithMessage(err, "could not write output file")
+	}
+
 	for _, tag := range tags.ToSlice() {
 		matchingPosts := []Post{}
 		for _, post := range posts {
@@ -344,27 +413,94 @@ func main() {
 				matchingPosts = append(matchingPosts, post)
 			}
 		}
-		err := os.MkdirAll(path.Join(outDir, "tags", tag), 0755)
-		check(err)
-		// tagPage := renderListPage(tag, config, matchingPosts)
-		// fmt.Printf("%+v\n", tagPage)
-		// err = os.WriteFile(path.Join(outDir, "tags", tag, "index.html"), []byte(tagPage), 0755)
-		// check(err)
+		if err := os.MkdirAll(path.Join(outDir, "tags", tag), 0755); err != nil {
+			return errors.WithMessage(err, "could not create directory")
+		}
+		tagPage, err := renderListPage(tag, *config, matchingPosts)
+		if err != nil {
+			return errors.WithMessage(err, "could not render tag page")
+		}
+		if err := os.WriteFile(path.Join(outDir, "tags", tag, "index.html"), []byte(tagPage), 0644); err != nil {
+			return errors.WithMessage(err, "could not write tag output file")
+		}
+
+		feedPage, 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")
+		}
+		if err := os.WriteFile(path.Join(outDir, "tags", tag, "atom.xml"), []byte(feedPage), 0644); err != nil {
+			return errors.WithMessage(err, "could not write tag feed output file")
+		}
+	}
+	listPage, err := renderListPage("", *config, posts)
+	if err != nil {
+		return errors.WithMessage(err, "could not render list page")
+	}
+	if err := os.WriteFile(path.Join(outDir, "post", "index.html"), []byte(listPage), 0644); err != nil {
+		return errors.WithMessage(err, "could not write list page output file")
+	}
+
+	feed, err := renderFeed(config.Title, *config, posts, "feed")
+	if err != nil {
+		return errors.WithMessage(err, "could not render feed")
+	}
+	if err := os.WriteFile(path.Join(outDir, "atom.xml"), []byte(feed), 0644); err != nil {
+		return errors.WithMessage(err, "could not write feed")
+	}
 
-		// fmt.Printf("%+v\n", renderFeed(fmt.Sprintf("%s - %s", config.Title, tag), config, matchingPosts, tag))
+	feedStyles, err := renderFeedStyles()
+	if err != nil {
+		return errors.WithMessage(err, "could not render feed styles")
+	}
+	if err := os.WriteFile(path.Join(outDir, "feed-styles.xsl"), []byte(feedStyles), 0644); err != nil {
+		return errors.WithMessage(err, "could not write feed styles")
+	}
 
-		// fmt.Printf("%+v\n", renderListPage("", config, posts))
+	homePage, err := renderHomepage(*config, posts)
+	if err != nil {
+		return errors.WithMessage(err, "could not render homepage")
+	}
+	if err := os.WriteFile(path.Join(outDir, "index.html"), []byte(homePage), 0644); err != nil {
+		return errors.WithMessage(err, "could not write homepage")
+	}
 
-		// fmt.Printf("%+v\n", renderFeed(config.Title, config, posts, "feed"))
+	notFound, err := render404(*config)
+	if err != nil {
+		return errors.WithMessage(err, "could not render 404 page")
+	}
+	if err := os.WriteFile(path.Join(outDir, "404.html"), []byte(notFound), 0644); err != nil {
+		return errors.WithMessage(err, "could not write 404 file")
+	}
 
-		// fmt.Printf("%+v\n", renderFeedStyles())
+	return nil
+}
 
-		// fmt.Printf("%+v\n", renderHomepage(config, posts))
+func main() {
+	if true {
+		slog.SetLogLoggerLevel(slog.LevelDebug)
+	}
+	slog.Debug("starting build process")
+	_, err := os.Getwd()
+	if err != nil {
+		log.Panic(errors.Errorf("working directory does not exist: %v", err))
+	}
 
-		fmt.Printf("%+v\n", render404(config))
-		fmt.Println(config.DefaultLanguage)
+	// log.SetFlags(log.Lshortfile)
+	if err := build(); err != nil {
+		switch cause := errors.Cause(err).(type) {
+		case *fs.PathError:
+			slog.Info("pathError")
+			slog.Error(fmt.Sprintf("%s", err))
+		case toml.ParseError:
+			slog.Info("parseError")
+			slog.Error(fmt.Sprintf("%s", err))
+		default:
+			slog.Info("other")
+			slog.Error(fmt.Sprintf("cause:%+v", errors.Cause(cause)))
+			slog.Error(fmt.Sprintf("%+v", cause))
+		}
+		os.Exit(1)
 	}
 
-	fmt.Printf("%+v\n", tags)
-	fmt.Println()
+	slog.Debug("done")
 }
diff --git a/go.mod b/go.mod
index dbebe7b..50fd8b8 100644
--- a/go.mod
+++ b/go.mod
@@ -3,18 +3,20 @@ module alanpearce.eu/website
 go 1.22.1
 
 require (
-	github.com/BurntSushi/toml v1.2.1 // indirect
-	github.com/PuerkitoBio/goquery v1.9.1 // indirect
-	github.com/adrg/frontmatter v0.2.0 // indirect
+	github.com/BurntSushi/toml v1.2.1
+	github.com/PuerkitoBio/goquery v1.9.1
+	github.com/adrg/frontmatter v0.2.0
+	github.com/antchfx/xmlquery v1.4.0
+	github.com/antchfx/xpath v1.3.0
+	github.com/deckarep/golang-set/v2 v2.6.0
+	github.com/pkg/errors v0.9.1
+	github.com/yuin/goldmark v1.7.1
+)
+
+require (
 	github.com/andybalholm/cascadia v1.3.2 // indirect
-	github.com/antchfx/xmlquery v1.4.0 // indirect
-	github.com/antchfx/xpath v1.3.0 // indirect
-	github.com/deckarep/golang-set/v2 v2.6.0 // indirect
 	github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
-	github.com/yuin/goldmark v1.7.1 // indirect
-	go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
 	golang.org/x/net v0.21.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
 	gopkg.in/yaml.v2 v2.3.0 // indirect
-	gopkg.in/yaml.v3 v3.0.1 // indirect
 )
diff --git a/go.sum b/go.sum
index de84a45..1431eeb 100644
--- a/go.sum
+++ b/go.sum
@@ -15,11 +15,11 @@ github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80N
 github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
 github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
 github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
 github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
-go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw=
-go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@@ -58,8 +58,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/internal/config/config.go b/internal/config/config.go
index aa46e6a..12b9395 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -1,7 +1,10 @@
 package config
 
 import (
+	"io/fs"
+
 	"github.com/BurntSushi/toml"
+	"github.com/pkg/errors"
 )
 
 type Taxonomy struct {
@@ -30,8 +33,19 @@ type Config struct {
 	Menus map[string][]MenuItem
 }
 
-func GetConfig() (error, Config) {
+func GetConfig() (*Config, error) {
 	config := Config{}
 	_, err := toml.DecodeFile("config.toml", &config)
-	return err, config
+	if err != nil {
+		var pathError *fs.PathError
+		var tomlError toml.ParseError
+		if errors.As(err, &pathError) {
+			return nil, errors.WithMessage(err, "could not read configuration")
+		} else if errors.As(err, &tomlError) {
+			return nil, errors.WithMessage(err, tomlError.ErrorWithUsage())
+		} else {
+			return nil, errors.Wrap(err, "config error")
+		}
+	}
+	return &config, nil
 }