wombat/converter/converter.go

36 lines
633 B
Go
Raw Normal View History

2019-01-01 19:41:03 +01:00
package converter
import (
"fmt"
2020-10-11 13:35:13 +02:00
goutil "git.gutmet.org/goutil.git/misc"
2019-01-01 19:41:03 +01:00
"github.com/russross/blackfriday/v2"
"os"
"sync"
)
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()
}