Debian Codegraph @

livereload/gen/livereload-hugo-plugin.js

raw
1 /*
2 Hugo adds a specific prefix, "__hugo_navigate", to the path in certain situations to signal
3 navigation to another content page.
4 */
5 function HugoReload() {}
6
7 HugoReload.identifier = 'hugoReloader';
8 HugoReload.version = '0.9';
9
10 HugoReload.prototype.reload = function (path, options) {
11 var prefix = '__hugo_navigate';
12
13 if (path.lastIndexOf(prefix, 0) !== 0) {
14 return false;
15 }
16
17 path = path.substring(prefix.length);
18
19 var portChanged = options.overrideURL && options.overrideURL != window.location.port;
20
21 if (!portChanged && window.location.pathname === path) {
22 window.location.reload();
23 } else {
24 if (portChanged) {
25 window.location = location.protocol + '//' + location.hostname + ':' + options.overrideURL + path;
26 } else {
27 window.location.pathname = path;
28 }
29 }
30
31 return true;
32 };
33
34 LiveReload.addPlugin(HugoReload);
35
36 // Disconnect LiveReload before the page is captured for a cross-document view
37 // transition. With Speculation Rules prerendering in Chromium, an active
38 // LiveReload WebSocket on the outgoing page causes a flash during the
39 // transition. LiveReload reconnects automatically on the next page load.
40 addEventListener('pageswap', function () {
41 if (window.LiveReload) {
42 window.LiveReload.shutDown();
43 }
44 });