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

View file

@ -1,8 +1,12 @@
package main package main
import ( import (
"bytes"
"log"
"os" "os"
"os/exec"
"path" "path"
"strings"
"text/template" "text/template"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
@ -27,7 +31,22 @@ type Task struct {
} }
func (t Task) Format(p *Page) (string, []byte) { 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. // DefaultConfig returns the default configuration.

View file

@ -14,5 +14,5 @@ destination = "public"
input = ".gmi" input = ".gmi"
output = ".html" output = ".html"
template = ".gmi" template = ".gmi"
postprocess = "geminiToHTML" postprocess = "geminitohtml"
destination = "public.html" destination = "public.html"