Commit graph

31 commits

Author SHA1 Message Date
Bjørn Erik Pedersen d02f0622b4 livereload: Improve the livereload script build and update to v4.0.2
This script has very infrequent updates, but just copy pasting the minified source creates some potential trust issues.

This JS will now be pulled from a Git version and both the unminified and minified version gets written to disk.

This way it should be easier to reason about changes in the future.

To upgrade, change the commit hash and run `mage generate`.

Closes #12451
Closes #6290
2024-05-10 22:33:08 +02:00
Christian Oliff 168d375784
all: Fix typos and some URLs 2024-02-18 12:16:30 +01:00
Bjørn Erik Pedersen 8adba648cc all: Remove unused code
Using x/tools/cmd/deadcode
2023-12-18 19:51:26 +01:00
Oleksandr Redko 9009c8cdca all: Fix typos in function names and comments 2023-06-19 09:26:29 +02:00
Bjørn Erik Pedersen 241b21b0fd Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
2023-05-16 18:01:29 +02:00
Bjørn Erik Pedersen 00ff161b67
livereload: Use text/javascript here, too 2022-10-26 12:54:50 +02:00
杨晴 3fefea06b8
commands: Fix embed in livereload.go 2022-08-01 11:42:26 +02:00
Takeshi Sato 21562e3aad
Externalise and embed livereload.js string
This is a small refactoring. `livereload/livereload.go` has a wide
column. Sometimes language server does not work because of it.
Create a new js file and embed it.
2022-07-26 13:51:08 +02:00
satotake 8e2fd55923 livereload: Use X-Forwarded-Host for Codespace
Codespace has 2 types of usage

1. in browser
2. vscode on local computer

As long as you select 2 (on local), Hugo handles livereload expectedly.
But if you use it in browser, Hugo does not reload on file change, as #9936 said.

This issue happens because `CheckOrigin` always fails.
Remote server could rewrite request host name.
Fix this by respecting `X-Forwarded-Host` header during origin checking

After merging this, you can preview changes lively with codespaece in browser.

```sh
hugo server --liveReloadPort 443
```

Close #9936
2022-06-05 11:16:24 +02:00
Bjørn Erik Pedersen d90e37e0c6 all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
2020-12-03 13:12:58 +01:00
Bjørn Erik Pedersen 2fc0abd22a
Fix livereload for @import case
Fixes #6106
2019-07-22 13:54:24 +02:00
Ivan Vyshnevskyi 2511498608 livereload: Fix host comparison when ports aren't present
Compare the original hosts from 'Origin' and 'Host' headers before
attempting to do a port-less comparison.  This helps in the case when
hugo server was started with a '--port=80' so both headers do not
contain a port.

Fixes #4141
2017-12-16 19:06:00 +01:00
Bjørn Erik Pedersen d99db71ab5
livereload: Fix recently broken window.location.reload logic
Closes #4100
2017-11-18 10:54:07 +01:00
Bjørn Erik Pedersen 60dfb9a6e0 Add support for multiple staticDirs
This commit adds support for multiple statDirs both on the global and language level.

A simple `config.toml` example:

```bash
staticDir = ["static1", "static2"]
[languages]
[languages.no]
staticDir = ["staticDir_override", "static_no"]
baseURL = "https://example.no"
languageName = "Norsk"
weight = 1
title = "På norsk"

[languages.en]
staticDir2 = "static_en"
baseURL = "https://example.com"
languageName = "English"
weight = 2
title = "In English"
```

In the above, with no theme used:

the English site will get its static files as a union of "static1", "static2" and "static_en". On file duplicates, the right-most version will win.
the Norwegian site will get its static files as a union of "staticDir_override" and "static_no".

This commit also concludes the Multihost support in #4027.

Fixes #36
Closes #4027
2017-11-17 11:01:46 +01:00
Yihui Xie 7231d5a829 livereload: Maintain the scroll position if possible
This fixes #3824: when the current pathname is the same as the one to be loaded, just call location.reload() so that the current scroll position can be preserved, instead of assigning to location.href, which will cause the scroll position to be lost.
2017-08-22 20:26:33 +02:00
Bjørn Erik Pedersen c825a73121 Support open "current content page" in browser
This commit adds a new `--navigateToChanged` and config setting with the same name, that, when running the Hugo server with live reload enabled, will navigate to the current content file's URL on save. 

This is really useful for site-wide content changes (copyedits etc.).
Fixes #3643
2017-06-26 21:34:16 +02:00
Bjørn Erik Pedersen 355736ec35 livereload: Fix data race in close
Fixes #2625
2017-04-30 01:10:57 +02:00
Cameron Moore 6affd31b3e livereload: Simplify RefreshPath 2016-12-28 11:09:50 +01:00
Bjørn Erik Pedersen 218fceac35 livereload: Add missing GoDoc 2016-03-24 14:05:08 +01:00
Anthony Fok bec1ac7b33 livereload: Run go fmt on connection.go
See #1998 and commit bafb771
2016-03-21 14:25:00 +08:00
srinivasreddy bafb77172b livereload: Simplify conditional 2016-03-20 19:42:10 +01:00
Anthony Fok ea75985c7d Update embedded livereload.js to 2.2.1 in livereload.go
Also add a copyright notice, download URL and the ugliflyjs command
used to update the livereloadJS variable.
2015-12-22 16:21:03 -07:00
Bjørn Erik Pedersen e445c35d6a Fix copyright headers in source files
Still need to add some missing headers and an AUTHORS file.

See #1646
2015-12-07 19:57:01 +01:00
Steve Francia f045d7a611 Change the license to Apache 2.0 2015-11-23 22:16:36 -05:00
bep 81c41d6f20 livereload: apply some Golint rules 2015-03-07 12:58:51 +01:00
bep ba53799fdb url_path => urlPath 2015-01-30 16:21:46 +01:00
Dan Hersam 523f38a9a8 Fix for issue 839 and 490 on Windows
The paths were seen as changed but not static because of the backslashes in
ev.Name. Once the backslashes were added, I discovered that the JSON
sent to livereload was invalid and failed to work because it had backslashes.

Hence the code to replace the backslashes from the path to make them work
in JSON and for the URL.

With this fix, changes to a stylesheet are shown on the page, and if it's a
single file that changed, it's reflected in the browser without reloading the whole
page.
2015-01-30 14:18:17 +01:00
bep 24bbfe7d32 Set Content-Type for livereload.js
The Content-Type was not set for livereload.js and was interpreteted by the browser as text/plain.

This commit sets it to application/javascript.

Fixes #562
2014-10-15 12:45:29 -04:00
bep df489b4712 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
2014-09-11 16:58:06 -04:00
spf13 79dd1d02b4 Fixing bug with Live Reload where it broadcast instead of sending the handshake 2014-05-27 18:35:12 -04:00
spf13 be1ee22032 Proper integration of live reload with automatic injection 2014-05-16 17:49:27 -04:00