Skip to content

Commit

Permalink
⚠ Print a warning when snowman build overwrites a file #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbe98 committed Oct 13, 2021
1 parent fec8d74 commit 159d468
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var buildCmd = &cobra.Command{
fmt.Println("Finished copying static files.")
}

var renderedPaths = make(map[string]bool)
for _, view := range discoveredViews {
results := make([]map[string]rdf.Term, 0)
if view.ViewConfig.QueryFile != "" {
Expand All @@ -121,14 +122,25 @@ var buildCmd = &cobra.Command{
if view.MultipageVariableHook != nil {
for _, row := range results {
outputPath := "site/" + strings.Replace(view.ViewConfig.Output, "{{"+*view.MultipageVariableHook+"}}", row[*view.MultipageVariableHook].String(), 1)

if renderedPaths[outputPath] {
fmt.Println("Warning: Writing to " + outputPath + " for the second time.")
}

if err := view.RenderPage(outputPath, row); err != nil {
return utils.ErrorExit("Failed to render page at "+outputPath, err)
}
renderedPaths[outputPath] = true
}
} else {
if renderedPaths["site/"+view.ViewConfig.Output] {
fmt.Println("Warning: Writing to " + "site/" + view.ViewConfig.Output + " for the second time.")
}

if err := view.RenderPage("site/"+view.ViewConfig.Output, results); err != nil {
return utils.ErrorExit("Failed to render page at "+"site/"+view.ViewConfig.Output, err)
}
renderedPaths["site/"+view.ViewConfig.Output] = true
}

}
Expand Down

0 comments on commit 159d468

Please sign in to comment.