mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
901077c036
commit
9442937d82
3 changed files with 55 additions and 27 deletions
|
@ -211,4 +211,7 @@ SUNSET2: {{ $resized2.RelPermalink }}/{{ $resized2.Width }}/Lat: {{ $resized2.Ex
|
|||
b.AssertFileContent("resources/_gen/images/sunset_17701188623491591036.json",
|
||||
"DateTimeDigitized|time.Time", "PENTAX")
|
||||
|
||||
// TODO(bep) add this as a default assertion after Build()?
|
||||
b.AssertNoDuplicateWrites()
|
||||
|
||||
}
|
||||
|
|
|
@ -486,6 +486,8 @@ func (s *sitesBuilder) CreateSitesE() error {
|
|||
return errors.Wrap(err, "failed to load config")
|
||||
}
|
||||
|
||||
s.Fs.Destination = hugofs.NewCreateCountingFs(s.Fs.Destination)
|
||||
|
||||
depsCfg := s.depsCfg
|
||||
depsCfg.Fs = s.Fs
|
||||
depsCfg.Cfg = s.Cfg
|
||||
|
@ -680,6 +682,12 @@ func (s *sitesBuilder) AssertImage(width, height int, filename string) {
|
|||
s.Assert(cfg.Height, qt.Equals, height)
|
||||
}
|
||||
|
||||
func (s *sitesBuilder) AssertNoDuplicateWrites() {
|
||||
s.Helper()
|
||||
d := s.Fs.Destination.(hugofs.DuplicatesReporter)
|
||||
s.Assert(d.ReportDuplicates(), qt.Equals, "")
|
||||
}
|
||||
|
||||
func (s *sitesBuilder) FileContent(filename string) string {
|
||||
s.T.Helper()
|
||||
filename = filepath.FromSlash(filename)
|
||||
|
|
|
@ -233,19 +233,26 @@ func (l *genericResource) Permalink() string {
|
|||
}
|
||||
|
||||
func (l *genericResource) Publish() error {
|
||||
fr, err := l.ReadSeekCloser()
|
||||
var err error
|
||||
l.publishInit.Do(func() {
|
||||
var fr hugio.ReadSeekCloser
|
||||
fr, err = l.ReadSeekCloser()
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
defer fr.Close()
|
||||
|
||||
fw, err := helpers.OpenFilesForWriting(l.spec.BaseFs.PublishFs, l.getTargetFilenames()...)
|
||||
var fw io.WriteCloser
|
||||
fw, err = helpers.OpenFilesForWriting(l.spec.BaseFs.PublishFs, l.getTargetFilenames()...)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
_, err = io.Copy(fw, fr)
|
||||
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -400,8 +407,10 @@ func (l genericResource) clone() *genericResource {
|
|||
return &l
|
||||
}
|
||||
|
||||
// returns an opened file or nil if nothing to write.
|
||||
func (l *genericResource) openDestinationsForWriting() (io.WriteCloser, error) {
|
||||
// returns an opened file or nil if nothing to write (it may already be published).
|
||||
func (l *genericResource) openDestinationsForWriting() (w io.WriteCloser, err error) {
|
||||
|
||||
l.publishInit.Do(func() {
|
||||
targetFilenames := l.getTargetFilenames()
|
||||
var changedFilenames []string
|
||||
|
||||
|
@ -412,14 +421,20 @@ func (l *genericResource) openDestinationsForWriting() (io.WriteCloser, error) {
|
|||
if _, err := l.getSpec().BaseFs.PublishFs.Stat(targetFilename); err == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
changedFilenames = append(changedFilenames, targetFilename)
|
||||
}
|
||||
|
||||
if len(changedFilenames) == 0 {
|
||||
return nil, nil
|
||||
return
|
||||
}
|
||||
|
||||
return helpers.OpenFilesForWriting(l.getSpec().BaseFs.PublishFs, changedFilenames...)
|
||||
w, err = helpers.OpenFilesForWriting(l.getSpec().BaseFs.PublishFs, changedFilenames...)
|
||||
|
||||
})
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (r *genericResource) openPublishFileForWriting(relTargetPath string) (io.WriteCloser, error) {
|
||||
|
@ -524,6 +539,8 @@ type permalinker interface {
|
|||
type resourceContent struct {
|
||||
content string
|
||||
contentInit sync.Once
|
||||
|
||||
publishInit sync.Once
|
||||
}
|
||||
|
||||
type resourceFileInfo struct {
|
||||
|
|
Loading…
Reference in a new issue