mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
dir: Return errors from executing process commands
This commit is contained in:
parent
d300bc23c0
commit
bfdbace471
13
dir.go
13
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 {
|
||||
|
|
8
funcs.go
8
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{} {
|
||||
|
|
Loading…
Reference in a new issue