diff --git a/dir.go b/dir.go index 31b478a..423f2f6 100644 --- a/dir.go +++ b/dir.go @@ -116,7 +116,9 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error { if cmd, ok := task.Preprocess[strings.TrimPrefix(ext, ".")]; ok { var buf bytes.Buffer - execute(cmd, bytes.NewReader(content), &buf) + if err := execute(cmd, bytes.NewReader(content), &buf); err != nil { + return err + } content = buf.Bytes() } page.Content = string(content) @@ -266,7 +268,9 @@ func (d *Dir) write(dstDir string, task *Task) error { var content []byte if cmd := task.Postprocess; cmd != "" { var buf bytes.Buffer - execute(cmd, strings.NewReader(page.Content), &buf) + if err := execute(cmd, strings.NewReader(page.Content), &buf); err != nil { + return err + } content = buf.Bytes() } else { content = []byte(page.Content) @@ -329,7 +333,7 @@ func (d *Dir) sort() { } // execute runs a command. -func execute(command string, input io.Reader, output io.Writer) { +func execute(command string, input io.Reader, output io.Writer) error { split := strings.Split(command, " ") cmd := exec.Command(split[0], split[1:]...) cmd.Stdin = input @@ -337,8 +341,9 @@ func execute(command string, input io.Reader, output io.Writer) { cmd.Stdout = output err := cmd.Run() if err != nil { - log.Fatal(err) + return err } + return nil } func (d *Dir) Title() string { diff --git a/funcs.go b/funcs.go index 7e40dd9..989f068 100644 --- a/funcs.go +++ b/funcs.go @@ -55,10 +55,12 @@ func (_strings) TrimRight(a, b string) string { return strings.TrimRight func (_strings) TrimSpace(s string) string { return strings.TrimSpace(s) } func (_strings) TrimSuffix(a, b string) string { return strings.TrimSuffix(a, b) } -func executeString(command, input string) string { +func executeString(command, input string) (string, error) { var b strings.Builder - execute(command, strings.NewReader(input), &b) - return b.String() + if err := execute(command, strings.NewReader(input), &b); err != nil { + return "", err + } + return b.String(), nil } func reverse(s interface{}) interface{} {