hexo-hotreload
Preface
hexo serve
连热重载都没有…
找不到可用的, 准备自己写
技术栈
后端监听文件 generate
事件, 通过 Websocket 发送信号
Start up
安装插件
Github: hexo-hotreload
npm i hexo-hotreload
插入代码
插入代码操作只在 0.0.1
版本中需要使用
更高版本已实现自动插入
在你想要进行热更新的页面插入
你可以在 url
框内键入 javascript:
并粘贴下面的内容
也可以直接将这些粘贴到 调试控制台
中
var h1=document.getElementsByTagName("h1"),article=document.querySelector("div.e-content")??document.getElementsByTagName("article")[0],title="";for(let k in h1)if(h1[k].className?.includes("title"))title=h1[k].innerText;if(title==="")throw new Error("Not find title, no article");var ws=new WebSocket("ws://localhost:3000");ws.addEventListener("open",function(){console.log("Connect Ok");ws.send(title)});ws.addEventListener("message",e=>{article.innerHTML=e.data});
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 静谧之园!