mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-11-23 17:12:18 +01:00
config: Implement support for postprocess commands
This commit is contained in:
parent
749fe58ccb
commit
9edacc1541
21
config.go
21
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.
|
||||
|
@ -14,5 +14,5 @@ destination = "public"
|
||||
input = ".gmi"
|
||||
output = ".html"
|
||||
template = ".gmi"
|
||||
postprocess = "geminiToHTML"
|
||||
postprocess = "geminitohtml"
|
||||
destination = "public.html"
|
||||
|
Loading…
Reference in New Issue
Block a user