mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-11 20:03:58 +02:00
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
This commit is contained in:
34
livereload/gen/livereload-hugo-plugin.js
Normal file
34
livereload/gen/livereload-hugo-plugin.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Hugo adds a specific prefix, "__hugo_navigate", to the path in certain situations to signal
|
||||
navigation to another content page.
|
||||
*/
|
||||
function HugoReload() {}
|
||||
|
||||
HugoReload.identifier = 'hugoReloader';
|
||||
HugoReload.version = '0.9';
|
||||
|
||||
HugoReload.prototype.reload = function (path, options) {
|
||||
var prefix = '__hugo_navigate';
|
||||
|
||||
if (path.lastIndexOf(prefix, 0) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
path = path.substring(prefix.length);
|
||||
|
||||
var portChanged = options.overrideURL && options.overrideURL != window.location.port;
|
||||
|
||||
if (!portChanged && window.location.pathname === path) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
if (portChanged) {
|
||||
window.location = location.protocol + '//' + location.hostname + ':' + options.overrideURL + path;
|
||||
} else {
|
||||
window.location.pathname = path;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
LiveReload.addPlugin(HugoReload);
|
Reference in New Issue
Block a user