Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

hexo-server-live

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-server-live - npm Package Compare versions

Comparing version
0.2.3
to
0.2.4
+5
-1
CHANGELOG.md

@@ -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>`);
});
{
"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",

}
}
}

@@ -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