36 lines
621 B
Go
36 lines
621 B
Go
package converter
|
|
|
|
import (
|
|
"fmt"
|
|
"git.gutmet.org/goutil.git"
|
|
"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()
|
|
}
|