sync: Markdown imports files using generic functions
This commit is contained in:
parent
b55151623c
commit
8723f500cc
1 changed files with 2 additions and 21 deletions
|
@ -3,9 +3,7 @@ package sync
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/base32"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
|
@ -89,27 +87,10 @@ func (t *imageImporterTransformer) Transform(doc *ast.Document, reader text.Read
|
|||
dPath := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(t.hash[:])), iPath)
|
||||
child.Destination = []byte(path.Join(t.absPath, string(child.Destination)))
|
||||
|
||||
if err := os.MkdirAll(path.Dir(dPath), 0755); err != nil {
|
||||
err := importFile(t.importer, path.Join(t.rootDir, iPath), dPath)
|
||||
if err != nil {
|
||||
return ast.WalkStop, err
|
||||
}
|
||||
|
||||
if fdto, err := os.Create(dPath); err != nil {
|
||||
return ast.WalkStop, err
|
||||
} else {
|
||||
defer fdto.Close()
|
||||
|
||||
if fd, closer, err := GetFile(t.importer, path.Join(t.rootDir, iPath)); err != nil {
|
||||
os.Remove(dPath)
|
||||
return ast.WalkStop, err
|
||||
} else {
|
||||
defer closer()
|
||||
|
||||
_, err = io.Copy(fdto, fd)
|
||||
if err != nil {
|
||||
return ast.WalkStop, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ast.WalkContinue, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue