mirror of
https://github.com/facundoolano/jorge.git
synced 2024-11-16 07:47:40 +01:00
35 lines
796 B
Go
35 lines
796 B
Go
package markup
|
|
|
|
import (
|
|
"io"
|
|
"slices"
|
|
|
|
"github.com/tdewolff/minify/v2"
|
|
"github.com/tdewolff/minify/v2/css"
|
|
"github.com/tdewolff/minify/v2/html"
|
|
"github.com/tdewolff/minify/v2/js"
|
|
"github.com/tdewolff/minify/v2/xml"
|
|
)
|
|
|
|
var SUPPORTED_MINIFIERS = []string{".css", ".html", ".js", ".xml"}
|
|
|
|
type Minifier struct {
|
|
minifier *minify.M
|
|
}
|
|
|
|
func LoadMinifier() Minifier {
|
|
minifier := minify.New()
|
|
minifier.AddFunc(".css", css.Minify)
|
|
minifier.AddFunc(".html", html.Minify)
|
|
minifier.AddFunc(".js", js.Minify)
|
|
minifier.AddFunc(".xml", xml.Minify)
|
|
return Minifier{minifier}
|
|
}
|
|
|
|
func (m *Minifier) Minify(extension string, contentReader io.Reader) io.Reader {
|
|
|
|
if !slices.Contains(SUPPORTED_MINIFIERS, extension) {
|
|
return contentReader
|
|
}
|
|
return m.minifier.Reader(extension, contentReader)
|
|
}
|