diff --git a/.golangci.yml b/.golangci.yml index c4d9eb0..4572dcc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,6 +7,7 @@ linters: - exhaustruct - paralleltest - gomoddirectives + - lll # linters deprecated - deadcode diff --git a/cli.go b/cli.go index 26ad470..a54845e 100644 --- a/cli.go +++ b/cli.go @@ -12,16 +12,22 @@ import ( ) type CLI struct { - BuildPath string `help:"where generated content should go" required:"" type:"path"` - LayoutFilename string `default:"layout.html" help:"layout file to render" required:""` + BuildPath string `help:"where generated content should go" required:"" type:"path"` + LayoutFilename string `default:"layout.html" help:"layout file to render" required:""` Serve bool `help:"serve when done building"` - SourcePath string `help:"source of all files" required:"" type:"path"` + SourcePath string `help:"source of all files" required:"" type:"path"` + AssetsPath string `help:"path to static assets (default with be source-path/public)"` } func (c *CLI) Run() error { + if c.AssetsPath == "" { + c.AssetsPath = filepath.Join(c.SourcePath, "public") + } + renderer := NewRender( filepath.Join(c.SourcePath, c.LayoutFilename), c.SourcePath, + c.AssetsPath, c.BuildPath, ) diff --git a/render.go b/render.go index 1447448..c461bff 100644 --- a/render.go +++ b/render.go @@ -29,6 +29,7 @@ import ( type Render struct { layoutPath string sourcePath string + assetsPath string buildPath string converter goldmark.Markdown } @@ -38,11 +39,13 @@ var errMissingTitle = errors.New("missing title in metadata or h1") func NewRender( layoutPath string, sourcePath string, + assetsPath string, buildPath string, ) *Render { return &Render{ layoutPath: layoutPath, sourcePath: sourcePath, + assetsPath: assetsPath, buildPath: buildPath, converter: goldmark.New( goldmark.WithRendererOptions( @@ -124,7 +127,7 @@ func (r *Render) copyAssets() error { return fmt.Errorf("could not create build path (%s): %w", r.buildPath, err) } - assetsPath := filepath.Join(r.sourcePath, "public") + assetsPath := r.assetsPath if _, err := os.Stat(assetsPath); !os.IsNotExist(err) { err = cp.Copy(assetsPath, r.buildPath)