about summary refs log tree commit diff stats
path: root/internal/content/posts.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/content/posts.go')
-rw-r--r--internal/content/posts.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/internal/content/posts.go b/internal/content/posts.go
index f4c6c76..467f36f 100644
--- a/internal/content/posts.go
+++ b/internal/content/posts.go
@@ -81,9 +81,8 @@ func RenderMarkdown(content []byte) (string, error) {
 }
 
 type Config struct {
-	Root      string
-	InputDir  string
-	OutputDir string
+	Root     string
+	InputDir string
 }
 
 func ReadPosts(config *Config, log *log.Logger) ([]Post, Tags, error) {
@@ -94,15 +93,15 @@ func ReadPosts(config *Config, log *log.Logger) ([]Post, Tags, error) {
 	if err != nil {
 		return nil, nil, errors.WithMessagef(err, "could not read post directory %s", subdir)
 	}
-	outputReplacer := strings.NewReplacer(config.Root, config.OutputDir, ".md", "/index.html")
-	urlReplacer := strings.NewReplacer(config.Root, "", ".md", "/")
+	outputReplacer := strings.NewReplacer(".md", "/index.html")
+	urlReplacer := strings.NewReplacer(".md", "/")
 	for _, f := range files {
-		pathFromRoot := filepath.Join(subdir, f.Name())
-		if !f.IsDir() && path.Ext(pathFromRoot) == ".md" {
-			output := outputReplacer.Replace(pathFromRoot)
-			url := urlReplacer.Replace(pathFromRoot)
-			log.Debug("reading post", "post", pathFromRoot)
-			matter, content, err := GetPost(pathFromRoot)
+		fn := f.Name()
+		if !f.IsDir() && path.Ext(fn) == ".md" {
+			output := path.Join(config.InputDir, outputReplacer.Replace(fn))
+			url := urlReplacer.Replace(strings.TrimPrefix("/", fn))
+			log.Debug("reading post", "post", fn)
+			matter, content, err := GetPost(path.Join(subdir, fn))
 			if err != nil {
 				return nil, nil, err
 			}
@@ -111,13 +110,13 @@ func ReadPosts(config *Config, log *log.Logger) ([]Post, Tags, error) {
 				tags.Add(strings.ToLower(tag))
 			}
 
-			log.Debug("rendering markdown in post", "post", pathFromRoot)
+			log.Debug("rendering markdown in post", "post", fn)
 			html, err := RenderMarkdown(content)
 			if err != nil {
 				return nil, nil, err
 			}
 			post := Post{
-				Input:      pathFromRoot,
+				Input:      fn,
 				Output:     output,
 				Basename:   filepath.Base(url),
 				URL:        url,