/
processor.go
51 lines (40 loc) · 1.08 KB
/
processor.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
40
41
42
43
44
45
46
47
48
49
50
51
package html
import (
"strings"
"github.com/mateussouzaweb/compactor/compactor"
)
// HTML processor
func Processor(context *compactor.Context) error {
content, perm, err := compactor.ReadFileAndPermission(context.Source)
if err != nil {
return err
}
content = strings.ReplaceAll(content, ".scss", ".css")
content = strings.ReplaceAll(content, ".sass", ".css")
content = strings.ReplaceAll(content, ".ts", ".js")
content = strings.ReplaceAll(content, ".tsx", ".js")
err = compactor.WriteFile(context.Destination, content, perm)
if err != nil {
return err
}
_, err = compactor.ExecCommand(
"html-minifier",
"--output", context.Destination,
"--collapse-whitespace",
"--remove-comments",
"--remove-optional-tags",
"--remove-redundant-attributes",
"--remove-script-type-attributes",
"--remove-style-link-type-attributes",
"--use-short-doctype",
"--minify-urls", "true",
"--minify-css", "true",
"--minify-js", "true",
"--ignore-custom-fragments", "/{{[{]?(.*?)[}]?}}/",
context.Destination,
)
if err == nil {
context.Processed = true
}
return err
}