Skip to content

Commit

Permalink
Allow whitespace in parameterized output paths #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbe98 committed Apr 5, 2024
1 parent be7fb63 commit a79c6de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/fs"
"io/ioutil"
"os"
"regexp"
"strings"

"github.com/glaciers-in-archives/snowman/internal/config"
Expand Down Expand Up @@ -141,7 +142,8 @@ var buildCmd = &cobra.Command{
return utils.ErrorExit("Failed to validate path section.", err)
}

outputPath := "site/" + strings.Replace(view.ViewConfig.Output, "{{"+*view.MultipageVariableHook+"}}", pathSection, 1)
outputVariablePattern := regexp.MustCompile(`{{ *` + *view.MultipageVariableHook + ` *}}`)
outputPath := "site/" + outputVariablePattern.ReplaceAllString(view.ViewConfig.Output, pathSection)

if renderedPaths[outputPath] {
fmt.Println("Warning: Writing to " + outputPath + " for the second time.")
Expand Down
2 changes: 1 addition & 1 deletion internal/views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func DiscoverViews(layouts []string) ([]View, error) {

for _, viewConf := range vConfigs.Views {
var multipageVariableHook *string
re := regexp.MustCompile(`{{([\w\d_]+)}}`)
re := regexp.MustCompile(`{{ *([\w\d_]+) *}}`)

This comment has been minimized.

Copy link
@despens

despens Apr 6, 2024

Shouldn't that regexp be:

{{\s*([\w\d_]+)\s*}} ??

Then it would catch any type of whitespace, such as tabulators. Not sure if that's relevant in yaml.

This comment has been minimized.

Copy link
@Abbe98

Abbe98 Apr 6, 2024

Author Collaborator

It's much easier to expand support than it's to remove it, so I'm being conservative on purpose. If there are cases in which it could be useful to support tabs or line-breaks I'm all for reviewing those separately.

if re.Match([]byte(viewConf.Output)) {
multipageVariableHook = &re.FindAllStringSubmatch(viewConf.Output, 1)[0][1]
}
Expand Down

0 comments on commit a79c6de

Please sign in to comment.