2019-01-01 19:41:03 +01:00
|
|
|
package converter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"sync"
|
2024-06-18 23:01:52 +02:00
|
|
|
|
|
|
|
goutil "git.fireandbrimst.one/aw/goutil/misc"
|
|
|
|
"github.com/russross/blackfriday/v2"
|
2019-01-01 19:41:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|