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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"io"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -89,28 +87,11 @@ 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)
|
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)))
|
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)
|
||||||
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 {
|
if err != nil {
|
||||||
return ast.WalkStop, err
|
return ast.WalkStop, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue