Search code examples
jekyll

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


I am running a jekyll server for a local site with bundle exec jekyll serve. When I make edits to a file in the site, jekyll regenerates the files automatically. I'd also like a script I have to be triggered to automatically to refresh my browser. How can I trigger this script?


Solution

  • In short words, run Jekyll with the --livereload parameter. The command will look like this:

    bundle exec jekyll serve --livereload
    

    For more information, call help command:

    jekyll help serve
    

    Here are the parameters that may be useful:

    -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
    

    You can of course combine options.

    For example: To run second project with Jekyll at the same time you need to set other port and another port for LiveReload.

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

    And now in your browser you can see the second project at http://localhost:4001/ or http://0.0.0.0:4001/