mirror of
https://github.com/facundoolano/jorge.git
synced 2024-12-26 21:58:51 +01:00
924e4629b2
* 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
36 lines
838 B
Go
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)
|
|
}
|