Exemple #1
0
func NewFavicon(path string) *Favicon {
	if !util.Fexists(path) {
		fmt.Println(fmt.Sprintf("%s not found", path))
		return nil
	}
	return &Favicon{Path: path}
}
Exemple #2
0
func RunAppend(dir, ex, in, out, js string) error {
	exs := strings.Split(ex, ",")
	ins := strings.Split(in, ",")
	dir, _ = filepath.Abs(dir)
	out, _ = filepath.Abs(out)
	if !util.Fexists(out) {
		err := os.Mkdir(out, os.ModePerm)
		if err != nil {
			fmt.Println(err.Error())
			return err
		}
	}
	cover_c := 0
	err := list(dir, out, func(path string) error {
		if match(exs, path) {
			return nil
		}
		if !match(ins, path) {
			return nil
		}
		defer func() {
			cover_c++
		}()
		opath := out + "/" + strings.TrimPrefix(path, dir)
		odir := filepath.Dir(opath)
		os.MkdirAll(odir, os.ModePerm)
		err := util.FCopy(path, opath)
		if err != nil {
			return err
		}
		return util.FAppend(opath, fmt.Sprintf(`
<script type="text/javascript" src="%s" ></script>
			`, js))
	})
	if err != nil {
		log.E("jcr error:%s", err.Error())
	} else {
		log.D("jcr execute success, %d file is covered...", cover_c)
	}
	return err
}