Beispiel #1
0
func (*minify) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var (
		buff bytes.Buffer
		err  error
	)

	switch m := min.New(); filepath.Ext(f.Path()) {
	case ".css":
		err = css.Minify(m, &buff, f, nil)
	case ".html", ".htm":
		err = html.Minify(m, &buff, f, nil)
	case ".js":
		err = js.Minify(m, &buff, f, nil)
	case ".json":
		err = json.Minify(m, &buff, f, nil)
	case ".svg":
		err = svg.Minify(m, &buff, f, nil)
	case ".xml":
		err = xml.Minify(m, &buff, f, nil)
	}

	if err != nil {
		return err
	}

	nf := goldsmith.NewFileFromData(f.Path(), buff.Bytes())
	nf.CopyValues(f)
	ctx.DispatchFile(nf)

	return nil
}
Beispiel #2
0
func Fuzz(data []byte) int {
	r := bytes.NewBuffer(data)
	err := html.Minify(minify.New(), ioutil.Discard, r, nil)
	if err != nil {
		panic(err)
	}
	return 1
}
func mini(renderBytes []byte) ([]byte, error) {
	m := minify.New()
	m.AddFunc("text/html", html.Minify)
	m.AddFunc("text/css", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error {
		_, err := io.Copy(w, r)
		return err
	})
	m.AddFunc("text/javascript", func(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error {
		_, err := io.Copy(w, r)
		return err
	})
	r := bytes.NewBuffer(renderBytes)
	w := &bytes.Buffer{}
	err := html.Minify(m, w, r, nil)

	return w.Bytes(), err
}