mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-28 21:21:40 -05:00
hugoblib: Fix "adding a bundle" in server mode
Before this commit, the live reload logic in `hugo server` got confused when you dropped a new bundle into the project while the server was running. The workaround was to restart the server. This commit fixes the "live reload bundle detection" in server mode, and also makes sure that the bundle headers are always processed first. Fixes #5075
This commit is contained in:
parent
0a88741fe8
commit
d139a037d9
2 changed files with 30 additions and 0 deletions
|
@ -740,6 +740,11 @@ func (m *contentChangeMap) resolveAndRemove(filename string) (string, string, bu
|
|||
}
|
||||
}
|
||||
|
||||
if isContent && fileTp != bundleNot {
|
||||
// A new bundle.
|
||||
return dir, dir, fileTp
|
||||
}
|
||||
|
||||
// Not part of any bundle
|
||||
return dir, filename, bundleNot
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -71,6 +72,30 @@ func newCapturer(
|
|||
numWorkers = n
|
||||
}
|
||||
|
||||
// TODO(bep) the "index" vs "_index" check/strings should be moved in one place.
|
||||
isBundleHeader := func(filename string) bool {
|
||||
base := filepath.Base(filename)
|
||||
name := helpers.Filename(base)
|
||||
return isContentFile(base) && (name == "index" || name == "_index")
|
||||
}
|
||||
|
||||
// Make sure that any bundle header files are processed before the others. This makes
|
||||
// sure that any bundle head is processed before its resources.
|
||||
sort.Slice(filenames, func(i, j int) bool {
|
||||
a, b := filenames[i], filenames[j]
|
||||
ac, bc := isBundleHeader(a), isBundleHeader(b)
|
||||
|
||||
if ac {
|
||||
return true
|
||||
}
|
||||
|
||||
if bc {
|
||||
return false
|
||||
}
|
||||
|
||||
return a < b
|
||||
})
|
||||
|
||||
c := &capturer{
|
||||
sem: make(chan bool, numWorkers),
|
||||
handler: handler,
|
||||
|
|
Loading…
Reference in a new issue