/
html.go
39 lines (32 loc) · 893 Bytes
/
html.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pretty
// github.com/tdewolff/minify binding for glub.
// No Configuration required.
import (
"sync"
"bytes"
"fmt"
"github.com/yosssi/gohtml"
"github.com/omeid/slurp"
)
func Pretty(c *slurp.C) slurp.Stage {
return func(in <-chan slurp.File, out chan<- slurp.File) {
var wg sync.WaitGroup
defer wg.Wait()
for file := range in {
wg.Add(1)
go func(file slurp.File) {
defer wg.Done()
html := new(bytes.Buffer)
_, err := html.ReadFrom(file.Reader)
if err != nil {
fmt.Println(err.Error())
return
}
pretty := bytes.NewBufferString(gohtml.Format(html.String()))
file.Reader = pretty
file.FileInfo.SetSize(int64(pretty.Len()))
out <- file
}(file)
}
}
}