1
0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-12-03 17:38:16 +01:00

config: Implement support for postprocess commands

This commit is contained in:
adnano 2021-04-11 17:23:01 -04:00
parent 749fe58ccb
commit 9edacc1541
2 changed files with 21 additions and 2 deletions

@ -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"