hexo-server-live
Advanced tools
+5
-1
@@ -0,5 +1,9 @@ | ||
| ## v0.2.4 (2024-01-16) | ||
| - Fix: auto reconnect SSE when server disconnects (#1). | ||
| ## v0.2.3 (2024-01-16) | ||
| - Feature: expose the option of whether to print reload info. | ||
| - Fix: disabled pjax for script type. | ||
| - Fix: disable pjax for script type. | ||
@@ -6,0 +10,0 @@ ## v0.2.2 (2024-01-16) |
+30
-15
| hexo.extend.filter.register("server_middleware", async (app) => { | ||
| const { basename, extname } = require("path"); | ||
| const log = require("hexo-log").default({ | ||
| const createLog = require("hexo-log"); | ||
| const log = createLog({ | ||
| name: "live-reload", | ||
| debug: false, | ||
@@ -12,3 +14,4 @@ silent: false | ||
| delay = 150, | ||
| info = true | ||
| info = true, | ||
| retry = 3000 | ||
| } = hexo.config.live_reload ?? {}; | ||
@@ -27,3 +30,3 @@ | ||
| const onProcessAfter = function(event) { | ||
| const onProcessAfter = function (event) { | ||
| if (event.type === "skip") return; | ||
@@ -69,4 +72,13 @@ if (resCollection.size === 0) return; | ||
| <script type="module"> | ||
| const es = new EventSource("${route}"); | ||
| es.addEventListener("${eventName}", (event) => { | ||
| let es = null; | ||
| function initES() { | ||
| es?.close(); | ||
| if (es == null || es.readyState == 2) { | ||
| es = new EventSource("${route}"); | ||
| es.onerror = function (e) { | ||
| if (es.readyState == 2) { | ||
| setTimeout(initES, ${retry}); | ||
| } | ||
| }; | ||
| es.addEventListener("${eventName}", (event) => { | ||
| const data = JSON.parse(event.data); | ||
@@ -77,14 +89,14 @@ | ||
| for (const link of links) { | ||
| const url = new URL(link.href); | ||
| if (url.host === location.host && url.pathname === data.path) { | ||
| const next = link.cloneNode(); | ||
| next.href = data.path + "?" + Math.random().toString(36).slice(2); | ||
| next.onload = () => link.remove(); | ||
| link.parentNode.insertBefore(next, link.nextSibling); | ||
| return; | ||
| } | ||
| const url = new URL(link.href); | ||
| if (url.host === location.host && url.pathname === data.path) { | ||
| const next = link.cloneNode(); | ||
| next.href = data.path + "?" + Math.random().toString(36).slice(2); | ||
| next.onload = () => link.remove(); | ||
| link.parentNode.insertBefore(next, link.nextSibling); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| if ("pjax" in window && data.type === "other") { | ||
| if ("pjax" in window) { | ||
| pjax.loadUrl(location.href, { history: false }); | ||
@@ -95,4 +107,7 @@ } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| initES(); | ||
| </script>`); | ||
| }); |
+2
-2
| { | ||
| "name": "hexo-server-live", | ||
| "version": "0.2.3", | ||
| "version": "0.2.4", | ||
| "description": "Live reload while source file changed for Hexo.", | ||
@@ -22,2 +22,2 @@ "main": "index", | ||
| } | ||
| } | ||
| } |
+3
-0
@@ -24,5 +24,8 @@ # hexo-server-live | ||
| delay: 150 | ||
| info: true | ||
| ``` | ||
| - **delay**: Reload delay after file updates | ||
| - **info**: Whether to print information when file updates | ||
| - **retry**: Delay for retrying to connect SSE | ||
@@ -29,0 +32,0 @@ ## License |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
6355
9.23%96
18.52%35
9.38%3
50%