mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-22 21:54:00 +00:00
Fixed #301. LiveReload works on any port now.
This commit is contained in:
parent
4076d77029
commit
7a8b754cad
2 changed files with 9 additions and 2 deletions
|
@ -83,6 +83,8 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
serverPort = sp.Port
|
serverPort = sp.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viper.Set("port", serverPort)
|
||||||
|
|
||||||
if serverAppend {
|
if serverAppend {
|
||||||
viper.Set("BaseUrl", strings.TrimSuffix(BaseUrl, "/")+":"+strconv.Itoa(serverPort))
|
viper.Set("BaseUrl", strings.TrimSuffix(BaseUrl, "/")+":"+strconv.Itoa(serverPort))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package transform
|
package transform
|
||||||
|
|
||||||
import "bytes"
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
func LiveReloadInject(content []byte) []byte {
|
func LiveReloadInject(content []byte) []byte {
|
||||||
match := []byte("</body>")
|
match := []byte("</body>")
|
||||||
|
port := viper.GetString("port")
|
||||||
replace := []byte(`<script>document.write('<script src="http://'
|
replace := []byte(`<script>document.write('<script src="http://'
|
||||||
+ (location.host || 'localhost').split(':')[0]
|
+ (location.host || 'localhost').split(':')[0]
|
||||||
+ ':1313/livereload.js?mindelay=10"></'
|
+ ':` + port + `/livereload.js?mindelay=10"></'
|
||||||
+ 'script>')</script></body>`)
|
+ 'script>')</script></body>`)
|
||||||
newcontent := bytes.Replace(content, match, replace, -1)
|
newcontent := bytes.Replace(content, match, replace, -1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue