Skip to content

Commit

Permalink
add default for asset path
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarchie committed Sep 27, 2023
1 parent 9d14fd8 commit 27a8e49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
- exhaustruct
- paralleltest
- gomoddirectives
- lll

# linters deprecated
- deadcode
Expand Down
12 changes: 9 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
5 changes: 4 additions & 1 deletion render.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type Render struct {
layoutPath string
sourcePath string
assetsPath string
buildPath string
converter goldmark.Markdown
}
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 27a8e49

Please sign in to comment.