about summary refs log tree commit diff stats
path: root/internal/content
diff options
context:
space:
mode:
Diffstat (limited to 'internal/content')
-rw-r--r--internal/content/posts.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/internal/content/posts.go b/internal/content/posts.go
index 5185d06..f4c6c76 100644
--- a/internal/content/posts.go
+++ b/internal/content/posts.go
@@ -8,15 +8,16 @@ import (
 	"slices"
 	"strings"
 	"time"
-	"website/internal/log"
+
+	"go.alanpearce.eu/x/log"
 
 	"github.com/adrg/frontmatter"
 	mapset "github.com/deckarep/golang-set/v2"
-	"github.com/pkg/errors"
 	fences "github.com/stefanfritsch/goldmark-fences"
 	"github.com/yuin/goldmark"
 	"github.com/yuin/goldmark/extension"
 	htmlrenderer "github.com/yuin/goldmark/renderer/html"
+	"gitlab.com/tozd/go/errors"
 )
 
 type PostMatter struct {
@@ -79,16 +80,22 @@ func RenderMarkdown(content []byte) (string, error) {
 	return buf.String(), nil
 }
 
-func ReadPosts(root string, inputDir string, outputDir string) ([]Post, Tags, error) {
+type Config struct {
+	Root      string
+	InputDir  string
+	OutputDir string
+}
+
+func ReadPosts(config *Config, log *log.Logger) ([]Post, Tags, error) {
 	tags := mapset.NewSet[string]()
 	posts := []Post{}
-	subdir := filepath.Join(root, inputDir)
+	subdir := filepath.Join(config.Root, config.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", "/")
+	outputReplacer := strings.NewReplacer(config.Root, config.OutputDir, ".md", "/index.html")
+	urlReplacer := strings.NewReplacer(config.Root, "", ".md", "/")
 	for _, f := range files {
 		pathFromRoot := filepath.Join(subdir, f.Name())
 		if !f.IsDir() && path.Ext(pathFromRoot) == ".md" {