func (t *thumbnail) Process(ctx goldsmith.Context, f goldsmith.File) error { defer ctx.DispatchFile(f) thumbPath, create := t.thumbName(f.Path()) if !create { return nil } var ( fn goldsmith.File err error ) if cached(ctx, f.Path(), thumbPath) { thumbPathDst := filepath.Join(ctx.DstDir(), thumbPath) fn, err = goldsmith.NewFileFromAsset(thumbPath, thumbPathDst) if err != nil { return err } } else { var err error fn, err = t.thumbnail(f, thumbPath) if err != nil { return err } } ctx.DispatchFile(fn) return nil }
func cached(ctx goldsmith.Context, srcPath, dstPath string) bool { srcPathFull := filepath.Join(ctx.SrcDir(), srcPath) srcStat, err := os.Stat(srcPathFull) if err != nil { return false } dstPathFull := filepath.Join(ctx.DstDir(), dstPath) dstStat, err := os.Stat(dstPathFull) if err != nil { return false } return dstStat.ModTime().Unix() >= srcStat.ModTime().Unix() }