enable configuration of static files to be copied
3 files changed, 20 insertions(+), 9 deletions(-)
M domain/content/builder/builder.go → domain/content/builder/builder.go
@@ -84,9 +84,10 @@ } log.Debug("reading posts", "source", options.Source) cc, err := content.NewContentCollection(&content.Config{ - Root: options.Source, - PostDir: postDir, - Repo: options.Repo, + Root: options.Source, + PostDir: postDir, + Repo: options.Repo, + StaticFiles: config.StaticFiles, }, log.Named("content")) if err != nil { return fault.Wrap(err)
M domain/content/posts.go → domain/content/posts.go
@@ -42,9 +42,10 @@ content []byte } type Config struct { - Root string - PostDir string - Repo *vcs.Repository + Root string + PostDir string + Repo *vcs.Repository + StaticFiles []string } type Collection struct {@@ -68,7 +69,6 @@ ".md", "", ) StaticList = []string{ "config.toml", - "cv.html", "public_key.asc", } )@@ -104,6 +104,8 @@ return buf.String(), nil } func NewContentCollection(config *Config, log *log.Logger) (*Collection, error) { + config.StaticFiles = append(config.StaticFiles, StaticList...) + cc := &Collection{ Posts: []*Post{}, Tags: mapset.NewSet[string](),@@ -138,6 +140,7 @@ return cc, nil } func (cc *Collection) HandleFile(filename string, d fs.DirEntry) error { + ext := strings.TrimPrefix(filepath.Ext(filename), ".") switch { case strings.HasPrefix(filename, ".") && filename != "." &&@@ -148,7 +151,8 @@ if d.Type().IsDir() { return fs.SkipDir } case !d.Type().IsDir(): - if filepath.Ext(filename) == ".md" { + switch ext { + case "md": if strings.HasPrefix(filename, cc.config.PostDir) { post, err := cc.GetPost(filename) if err != nil {@@ -166,8 +170,12 @@ return err } cc.Pages = append(cc.Pages, page) } - } else if slices.Contains(StaticList, filename) { + case "html": cc.StaticFiles = append(cc.StaticFiles, filename) + default: + if slices.Contains(cc.config.StaticFiles, filename) { + cc.StaticFiles = append(cc.StaticFiles, filename) + } } }