wombat/converter/converter.go
2024-06-18 23:01:52 +02:00

37 lines
640 B
Go

package converter
import (
"fmt"
"os"
"sync"
goutil "git.fireandbrimst.one/aw/goutil/misc"
"github.com/russross/blackfriday/v2"
)
func convert(f string) {
outfile := f[0:len(f)-len(".md")] + ".html"
input, err := goutil.ReadFile(f)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
output := string(blackfriday.Run([]byte(input)))
goutil.WriteFile(outfile, output)
err = os.Remove(f)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func ConvertAll(files []string) {
var wg sync.WaitGroup
wg.Add(len(files))
for _, f := range files {
go func(file string) {
defer wg.Done()
convert(file)
}(f)
}
wg.Wait()
}