diff --git a/config.go b/config.go index 50ce170..71ecd3f 100644 --- a/config.go +++ b/config.go @@ -1,8 +1,12 @@ package main import ( + "bytes" + "log" "os" + "os/exec" "path" + "strings" "text/template" "github.com/BurntSushi/toml" @@ -27,7 +31,22 @@ type Task struct { } func (t Task) Format(p *Page) (string, []byte) { - return path.Join(p.Path, "index"+t.Output), []byte(p.Content) + path := path.Join(p.Path, "index"+t.Output) + + // Run a custom command. + if t.PostProcess != "" { + split := strings.Split(t.PostProcess, " ") + cmd := exec.Command(split[0], split[1:]...) + buf := new(bytes.Buffer) + cmd.Stdin = strings.NewReader(p.Content) + cmd.Stdout = buf + if err := cmd.Run(); err != nil { + log.Fatal(err) + } + return path, buf.Bytes() + } + + return path, []byte(p.Content) } // DefaultConfig returns the default configuration. diff --git a/example/config.toml b/example/config.toml index 746c34f..90720fd 100644 --- a/example/config.toml +++ b/example/config.toml @@ -14,5 +14,5 @@ destination = "public" input = ".gmi" output = ".html" template = ".gmi" -postprocess = "geminiToHTML" +postprocess = "geminitohtml" destination = "public.html"