Exemplo n.º 1
0
func Convert(j *job.Job) {
	go safely.Do(logger, j, FriendlyMessage, func() {
		writeHTML(j)
		cmd := exec.Command(kindlegen, []string{j.HTMLFilename()}...)
		cmd.Dir = j.Root()
		out, err := cmd.CombinedOutput()
		if !util.FileExists(j.MobiFilePath()) {
			logger.Panicf("Failed running kindlegen: %s {output=%s}", err.Error(), string(out))
		}
		j.Progress("Conversion complete...")
		postmark.Mail(j)
	})
}
Exemplo n.º 2
0
func rewriteAndDownloadImages(j *job.Job, doc *h5.Node) *h5.Node {
	var wg sync.WaitGroup
	root := j.Root()
	t := transform.NewTransform(doc)
	fix := transform.TransformAttrib("src", func(uri string) string {
		altered := fmt.Sprintf("%x.jpg", hashie.Sha1([]byte(uri)))
		wg.Add(1)
		go safely.Ignore(logger, func() {
			defer wg.Done()
			downloadToFile(uri, fmt.Sprintf("%s/%s", root, altered))
		})
		return altered
	})
	t.Apply(fix, "img")
	wg.Wait()
	return t.Doc()
}
Exemplo n.º 3
0
func makeRoot(j *job.Job) {
	if err := os.MkdirAll(j.Root(), 0755); err != nil {
		logger.Panicf("Failed to make working directory: %s", err.Error())
	}
}