mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Copy static files changed
Fix watcher copy static theme files for changed files See #1644 #1559
This commit is contained in:
parent
f310492cb0
commit
8f6f13104e
1 changed files with 21 additions and 13 deletions
|
@ -452,7 +452,7 @@ func copyStatic() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the site's own static directory
|
// Copy the site's own static directory
|
||||||
staticDir := helpers.AbsPathify(viper.GetString("StaticDir")) + helpers.FilePathSeparator
|
staticDir := helpers.GetStaticDirPath() + helpers.FilePathSeparator
|
||||||
if _, err := os.Stat(staticDir); err == nil {
|
if _, err := os.Stat(staticDir); err == nil {
|
||||||
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
|
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
|
||||||
return syncer.Sync(publishDir, staticDir)
|
return syncer.Sync(publishDir, staticDir)
|
||||||
|
@ -572,7 +572,7 @@ func NewWatcher(port int) error {
|
||||||
|
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
ext := filepath.Ext(ev.Name)
|
ext := filepath.Ext(ev.Name)
|
||||||
istemp := strings.HasSuffix(ext, "~") || (ext == ".swp") || (ext == ".swx") || (ext == ".tmp") || strings.HasPrefix(ext, ".goutputstream") || strings.HasSuffix(ext, "jb_old___")|| strings.HasSuffix(ext, "jb_bak___")
|
istemp := strings.HasSuffix(ext, "~") || (ext == ".swp") || (ext == ".swx") || (ext == ".tmp") || strings.HasPrefix(ext, ".goutputstream") || strings.HasSuffix(ext, "jb_old___") || strings.HasSuffix(ext, "jb_bak___")
|
||||||
if istemp {
|
if istemp {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -598,9 +598,7 @@ func NewWatcher(port int) error {
|
||||||
dynamicChanged = dynamicChanged || !isstatic
|
dynamicChanged = dynamicChanged || !isstatic
|
||||||
|
|
||||||
if isstatic {
|
if isstatic {
|
||||||
if staticPath, err := helpers.MakeStaticPathRelative(ev.Name); err == nil {
|
staticFilesChanged[ev.Name] = true
|
||||||
staticFilesChanged[staticPath] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add new directory to watch list
|
// add new directory to watch list
|
||||||
|
@ -633,16 +631,26 @@ func NewWatcher(port int) error {
|
||||||
publishDir = ""
|
publishDir = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for path := range staticFilesChanged {
|
staticDir := helpers.GetStaticDirPath()
|
||||||
staticPath := filepath.Join(helpers.AbsPathify(viper.GetString("StaticDir")), path)
|
themeStaticDir := helpers.GetThemesDirPath()
|
||||||
jww.FEEDBACK.Printf("Syncing file '%s'\n", staticPath)
|
|
||||||
|
|
||||||
if _, err := os.Stat(staticPath); err == nil {
|
jww.FEEDBACK.Printf("StaticDir '%s'\nThemeStaticDir '%s'\n", staticDir, themeStaticDir)
|
||||||
publishPath := filepath.Join(publishDir, path)
|
|
||||||
jww.INFO.Println("syncing from", staticPath, "to", publishPath)
|
for path := range staticFilesChanged {
|
||||||
err := syncer.Sync(publishPath, staticPath)
|
var publishPath string
|
||||||
|
|
||||||
|
if strings.HasPrefix(path, staticDir) {
|
||||||
|
publishPath = filepath.Join(publishDir, strings.TrimPrefix(path, staticDir))
|
||||||
|
} else if strings.HasPrefix(path, themeStaticDir) {
|
||||||
|
publishPath = filepath.Join(publishDir, strings.TrimPrefix(path, themeStaticDir))
|
||||||
|
}
|
||||||
|
jww.FEEDBACK.Printf("Syncing file '%s'", path)
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
jww.INFO.Println("syncing from ", path, " to ", publishPath)
|
||||||
|
err := syncer.Sync(publishPath, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jww.FEEDBACK.Printf("Error on syncing file '%s'\n", staticPath)
|
jww.FEEDBACK.Printf("Error on syncing file '%s'\n", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue