本地 jekyll 文件更改时如何触发脚本?

How can I trigger a script when local jekyll file changes?

我是 运行 本地站点的 jekyll 服务器 bundle exec jekyll serve。当我对站点中的文件进行编辑时,jekyll 会自动重新生成文件。我还想要一个脚本,我必须被触发才能自动刷新我的浏览器。我怎样才能触发这个脚本?

简而言之,运行 Jekyll 带有 --livereload 参数。 该命令将如下所示:

bundle exec jekyll serve --livereload

更多信息,调用帮助命令:

jekyll help serve

以下是可能有用的参数:

-l, --livereload   Use LiveReload to automatically refresh browsers
    --livereload-ignore ignore GLOB1[,GLOB2[,...]]  Files for LiveReload to ignore. Remember to quote the values so your shell won't expand them
    --livereload-min-delay [SECONDS]  Minimum reload delay
    --livereload-max-delay [SECONDS]  Maximum reload delay
    --livereload-port [PORT]  Port for LiveReload to listen on

您当然可以组合选项。

例如: 要同时使用 Jekyll 运行 第二个项目,您需要设置其他端口和 LiveReload 的另一个端口。

bundle exec jekyll serve --livereload --livereload-port 8080 --port 4001

现在在您的浏览器中您可以在 http://localhost:4001/ 或 http://0.0.0.0:4001/

看到第二个项目