jorge/markup/minify.go
Facundo Olano 924e4629b2
Add smart quotes replacement in output html (#14)
* first basic implementation with gojekyll port

* extract smartify file

* template struct comments

* rename templates package to markup

* move minify file to markup

* move html to markup

* move smartify to markup

* first stab at unit test

* better dash replacement

* do plain replacement of dashes
2024-02-26 12:16:06 -03:00

36 lines
838 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}
}
// if enabled by config, minify web files
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)
}