diff options
author | Alan Pearce | 2025-01-24 22:14:22 +0100 |
---|---|---|
committer | Alan Pearce | 2025-01-24 22:18:34 +0100 |
commit | 177955eab572c13b7d99217e54250f377c9a3c9e (patch) | |
tree | 49bf935309446867fd3a6c30f1cf35605648e7b0 /internal/content/posts.go | |
parent | e2b10dee160b5b1a7e06dfb34c137d2a43bccd91 (diff) | |
download | website-177955eab572c13b7d99217e54250f377c9a3c9e.tar.lz website-177955eab572c13b7d99217e54250f377c9a3c9e.tar.zst website-177955eab572c13b7d99217e54250f377c9a3c9e.zip |
abstract builder outputs
Diffstat (limited to 'internal/content/posts.go')
-rw-r--r-- | internal/content/posts.go | 25 |
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, |