mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Enable soft livereload of CSS and images
Prior to this commit a dummy JavaScript filename was sent to LiveReload when changing a static file (CSS, image etc.), forcing a full browser reload of the page. This commit fixes this by sending the relative file path of the changed static resource, enabling partial live reloading for CSS- and image-changes. If more than one static file happens to end up in the same changeevent-batch, it will fall back to do a full refresh. To enable this logic, the change events with names ending with ".goutputstream*" is now filtered out as temporary. Changes in dynamic content behaves like before. Issue #490
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -130,6 +131,23 @@ func AbsPathify(inPath string) string {
|
||||
return filepath.Clean(filepath.Join(viper.GetString("WorkingDir"), inPath))
|
||||
}
|
||||
|
||||
func MakeStaticPathRelative(inPath string) (string, error) {
|
||||
staticDir := AbsPathify(viper.GetString("StaticDir"))
|
||||
themeStaticDir := AbsPathify("themes/"+viper.GetString("theme")) + "/static/"
|
||||
|
||||
return MakePathRelative(inPath, staticDir, themeStaticDir)
|
||||
}
|
||||
|
||||
func MakePathRelative(inPath string, possibleDirectories ...string) (string, error) {
|
||||
|
||||
for _, currentPath := range possibleDirectories {
|
||||
if strings.HasPrefix(inPath, currentPath) {
|
||||
return strings.TrimPrefix(inPath, currentPath), nil
|
||||
}
|
||||
}
|
||||
return inPath, errors.New("Can't extract relative path, unknown prefix")
|
||||
}
|
||||
|
||||
func Filename(in string) (name string) {
|
||||
name, _ = FileAndExt(in)
|
||||
return
|
||||
|
Reference in New Issue
Block a user